开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜