Return these records from some parents, of whom their children have a certain property equal to a certain value?
2 answers
This is your request:
parents = parents.Where(p => p.children.Any(c => c.property1 == "Something")).ToList();
Enumerable.Where filters a sequence of values based on a predicate, while Enumerable.Select projects each element of the sequence into a new shape.
Enumerable.Any will return true if there is at least 1 child with porperty1 equal to "something"
Like all you have to do is filtering, you just have to useWhere
. You would use Select
if you wanted to create a collection of some type other than the parent itself.
+2
source to share