选择基于null

时间:2011-05-08 19:26:23

标签: c# linq

我正在构建一个动态查询并在两个实体之间进行连接:正在构建的查询和一个表。

我有:

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

感谢您的建议。

1 个答案:

答案 0 :(得分:2)

要使用LINQ进行左外连接,您必须使用join .. intoDefaultIfEmpty()

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