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

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

 var agencies = from a in agencyList
                           join aa in joinTable
                           on a.AgencyId equals aa.AgencyId into joined
                           from aa in joined.DefaultIfEmpty()
                           where aa == null)
                           select a;

But this does not exclude non-zero values ​​of aa and returns all records in the same way as if "where aa == null" was not.

Any help is appreciated. Thank.

+3
source share
1 answer

What about:

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

Source: https://habr.com/ru/post/1746442/


All Articles