Find all entities using lambda

c#, linq

Solution

It's as simple as SelectMany:

Projects each element of a sequence to an IEnumerable and flattens the resulting sequences into one sequence.

var kids = people.SelectMany(p => p.Kids);

(If you want a `List<Kid>` instead of an `IEnumerable<Kid>`, just call `.ToList()` on the result.)

Problem

I have a `List<Person>` (people) every person has a `List<Kid>` (kids) If I want to find all the kids, in LINQ this is what I would do ``` var kids=new List<Kids>(); foreach(var p in people) { foreach(var kid in p.Kids) { kids.Add(kid); } } ``` Is there a one line way of doing this using LINQ?

Original source