0

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!

1 Answer 1

1

Did you try?

where s.Projects.Count() == 0
Sign up to request clarification or add additional context in comments.

2 Comments

hah that worked.. I'm new to C# and I never knew about the fact that I get an ICollection property after i declare a 1 -> * rel. Thanks heaps! Will accept your answer as correct after 5 mins
Even better, !s.Projects.Any(); Count always iterates the collection, but Any just returns true if it finds something. It's a minor improvement, but there's no reason not to do it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.