Dragan
Dragan

Reputation: 3743

entity framework / linq query construction

I have the following tables:

Project:

Id
SettlementId
...

Settlement

Id
Name
AreaId

Area

Id
Name
...

I need to get all settlements that belong to a particular area (i get the areaId from the selected dropdownlist) that are not part of any project.

So far this is my query:

var settlements = (from s in entities.Settlements
                  where s.AreaId == selectedAreaId
                  select s).toList();

Am not entirely sure how to filter out the settlements that are already part of an existing project.

Thanks for your time!

Upvotes: 0

Views: 97

Answers (1)

Johann Blais
Johann Blais

Reputation: 9469

Did you try?

where s.Projects.Count() == 0

Upvotes: 1

Related Questions