Reputation: 68840
I have a Country object which has States. Each state has a Persons collection. (Simplified, but the structure is the same)
I am trying to find out how many people in the country have person.IsAlive==true
I'm trying something like
country.States.SelectMany(e=>e.Persons...).Count
but loose it there.
Items?
Upvotes: 0
Views: 41
Reputation: 66511
You're really close. Select the IsAlive
property, and perform a Count
on the matching records:
country.States.SelectMany(e => e.Persons.Where(p => p.IsAlive)).Count();
Upvotes: 3