tags:

views:

116

answers:

2

Hi. 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.DefaultIfEmpty()
                           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.

+1  A: 

What about:

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

Thanks. Both solutions are actually correct. My query to retrieve my join table was incorrect. Thanks.

kmehta