Order parent collection by minimum values in child collection in Linq

Viewed 1296
Parent{ List<Child> Children {get;set;} }
Child { int Age {get;set;} }

I would like to order the parents by the lowest age of their children, proceeding to the second or third child in the case of a tie.

The closest I've come is this, which only orders by the youngest child:

parents.OrderBy(p => p.Children.Min(c => c.Age))

This doesn't account for second (or third, etc) youngest in the case of a tie.

Given these 3 parents with corresponding child ages, I'd like them to come out in this order.

  • P1 1,2,7
  • P2 1,3,6
  • P3 1,4,5
3 Answers
Related