score:2
Accepted answer
Try this linq. To exclude duplicates from minorClients
, I've used Contains
method. To union all objects - Union
method:
var majorClients = from maj in dbContext.MajorClients
where maj.startdate > startDate
&& maj.status == "Active"
select new Client
{
EntityPK = maj.mjPrimaryKey,
Name = maj.name,
Type = "Maj"
};
var minorClients = from min in dbContext.MinorClients
where min.startdate > startDate
&& min.status == "Active" || min.status== "Inactive"
&& !(from maj in dbContext.MajorClients
where maj.startdate > startDate
&& maj.status == "Active"
select maj.name).Contains(min.Name)
select new Client
{
EntityPK = min.mnPrimaryKey,
Name = min.name,
Type = "Min"
};
var allClients = majorClients.Union(minorClients);
Source: stackoverflow.com
Related Query
- Linq union all equivalent of sql code
- LINQ equivalent of my SQL Query for UNION ALL
- Equivalent C# LINQ code for SQL
- Convert union all and Subquery SQL query to LINQ
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- What is the linq equivalent to the SQL IN operator
- How are people unit testing code that uses Linq to SQL
- How can I do a Union all in Entity Framework LINQ To Entities?
- how to convert sql union to linq
- Python equivalent of LINQ All function?
- Equivalent of SQL Between Statement Using Linq or a Lambda expression
- performance of LINQ queries against the SQL equivalent
- What is SQL equivalent to LINQ .All()
- LINQ to Entities equivalent of sql "TOP(n) WITH TIES"
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- LINQ to SQL . how to select all record using .take()
- linq equivalent sql query "not in (select query)"
- Seemingly equivalent queries in LINQ and SQL returns different results
- linq equivalent of 'select *' sql for generic function?
- Linq Query Where() SQL % equivalent
- LINQ Source Code Available
- Is it possible to automatically prefix all table names in SQL Server and in LINQ to SQL?
- Linq to SQL C# Get Products in all child/sub child Categories too slow
- Case Query in LINQ equivalent to sql query
- Create Linq Expression for Sql Equivalent "column is null" in c# by creating linq query dynamically
- Delete all records from a database using LINQ to SQL
- EF: Is there way to force Linq using UNION instead of UNION ALL
- Linq equivalent of SQL LEFT function?
- Linq with Lambda equivalent of SQL
- LINQ equivalent of SQL IsNull(..,..) in the Where Clause
More Query from same tag
- Two different LINQ queries against the same Entity Framework DbSet, both return the same results
- How to use LINQ Where for generic type?
- How do I find the count of overlapping properties in SQL/LINQ query between two tables?
- LINQ to EF - Simulating SQL "IN" clause
- insert linq query in many to many relation in asp.net mvc
- SqlDateTime overflow when inserting value with DateTime.Now
- Inserting particular XElement at specific position in a XML using LINQ
- Linq If Statement
- Index out of range error
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- LINQ returns different sort order for same function
- iterate over record in generic list
- What's the difference between FindAll and Select?
- LINQ query to fetch bus number taking two records
- Reading from .csv-file into double-array
- Understanding .AsEnumerable() in LINQ to SQL
- Remove Duplicates From List<T> Based on Property Selected By Lambda
- Cannot implicitly convert type 'System.Linq.IQueryable<double>' to 'double'
- C# Web API LINQ Entity Queries - Cast AnonymousType to Class-Object
- How to skip to substring in list
- Integrate NULL check in LINQ
- C# Linq how to compare two strings and report the first different char which is itself different from '?' wildcard
- XDocument Error Nonwhitespace
- Linq query to pick up field if it is null or matches specific value
- LINQ query to Observable collection
- Find a collection property using reflection then add to collection
- Error: DbContext has been disposed
- Add new record var LINQ
- Grouping/sorting with Linq
- LINQ how to project a list while combining properties of object