selecting based on null
I'm building a dynamic query and doing a join between 2 entities: the query being built and a table.
I have:
var TheQuery = ...;
TheQuery = from x in TheQuery
join c in MyDataContext.TheTable on
x.ID equals c.ID
开发者_C百科 where "there's no matching element in TheTable"
select x
Thanks for your suggestions.
To do a Left outer join with LINQ you have to use join .. into
and DefaultIfEmpty()
:
TheQuery = from x in TheQuery
join c in MyDataContext.TheTable on x.ID equals c.ID into outer
from o in outer.DefaultIfEmpty()
where o == null
select x
精彩评论