开发者

LINQ, Left Join, Only Get where null in join table

开发者 https://www.devze.com 2022-12-30 20:51 出处:网络
I am trying to do a left outer join on two tables, but I only want to return the results from the first table where the second table does not have a record (null).

I am trying to do a left outer join on two tables, but I only want to return the results from the first table where the second table does not have a record (null).

 var agencies = from a in agencyList
                           join aa in joinTable
                           on a.AgencyId equals aa.AgencyId into joined
                           from aa in joined.DefaultIfEmp开发者_运维知识库ty()
                           where aa == null)
                           select a;

But this does not exclude the non null values of aa, and returns all the records just the same as if the 'where aa == null' was not there.

Any help is appreciated. Thanks.


What about:

var agencies = from a in agencyList
                           where (from aa in joinTable where aa.AgencyId == a.AgencyId select aa).Count() == 0
                           select a;
0

精彩评论

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