我正在构建一个动态查询并在两个实体之间进行连接:正在构建的查询和一个表。
我有:
var TheQuery = ...;
TheQuery = from x in TheQuery
join c in MyDataContext.TheTable on
x.ID equals c.ID
where "there's no matching element in TheTable"
select x
感谢您的建议。
答案 0 :(得分:2)
要使用LINQ进行左外连接,您必须使用join .. into
和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