我正在构建一个动态查询,并在两个实体之间进行联接:正在构建的查询和一个表。
我有:
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
感谢您的建议。
要使用 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