I have a list of objects with the following basic structure:
class Person { public int ID {get; set;} public bool ShowChildren {get; set;} public int ParentID {get; set;}
I need to return a list of parent Person classes that are ordered by their identifier. If the ShowChildren flag is enabled, also return children under the parent, sorted by their identifier.
This is only one level of depth, that is, children will not have children.
I can write a linq statement to give me all the parents, but I was fixated on how to enable also sorted children when the parent flag is on.
var People = PersonList .Where(x => x.ParentID == 0) .Orderby(x => x.ID) .ToList();
source share