I have a list of Parent objects that has a list of Children objects. I need to write a query that would give me the parent that has the most children. The ORM is entity framework, so it should work with that.
Code to start with:
parents.FirstOrDefault(c => c.Children.Max());
Something like that.
I think it should look more like this:
Your query is not correct, because
c.Children.Max()will try to iterate over children of one parent, and if they support comparison (e.g. children are Ints), will simply return biggest of them. And most probably your Children objects are not bool, so you won’t be able to even compile the code, because FirstOrDefault takes