0

I have two tables, Address & People. People has FK to Address. I'm trying to find addresses where there are no people:

select id from Address a 
left outer join person p on p.address_id = a.id
where p.address_id is null

Is this possible using LINQ to Entities? I tried a few variations around

 var results = from addr in _context.Addresses
               from ppl in addr.People
               where ppl == null ...

but can't seem to figure out how to return addresses where there are no people.

chris
  • 36,094
  • 53
  • 157
  • 237

1 Answers1

0

I propose:

var results = (from addr in _context.Addresses
               where !addr.People.Any()
               select addr).ToList();
Slauma
  • 175,098
  • 59
  • 401
  • 420