This title is the worst ...
In any case, I'm trying to select a parent that contains n number of children. I will pass a list of criteria (1..n) that the child objects must match. For brevity, here are the classes I'm working with:
public class Parent {
public int Id { get; set; }
public List<Child> Children { get; set; }
}
public class Child {
public int Id { get; set; }
public int ParentId { get; set; }
public int SomeValue { get; set; }
}
I am looking for a list of parents that contain children that match all SomeValues that I pass
So, if I have:
Parent 1
Child 1, SomeValue 10
Child 2, SomeValue 20
Child 3, SomeValue 40
Parent 2
Child 4, SomeValue 10
Child 5, SomeValue 20
Child 5, SomeValue 50
and myList - [10, 50], it should return only parent 2. If myList [10, 20], then both parents should be returned. And finally, if myList [10, 20, 60], nothing needs to be returned.
, , , , , (?)
parents.where(p => p.children.all(c => myList.contains(c.SomeValue)));
, -, . , , myList. , , , myList.length, , SomeValue ( , SomeValues?)