Ryan Lege
Ryan Lege

Reputation: 167

LINQ Query-Select records where all the children meet a condition

I have a One to Many relationship. I want to select all records from the parent table where it's children all meet a specific condition. If one of the children fails then that record is not returned.

Upvotes: 2

Views: 3294

Answers (1)

Balthy
Balthy

Reputation: 906

Something like:

var results = parentCollection.Where(p => p.Children.All(c => <condition>));

Should do the trick.

Upvotes: 5

Related Questions