I have an enumerated list containing a flattened parent-child relationship:
ParentGuid1, ParentName1, ChildGuid1, ChildName1 ParentGuid1, ParentName1, ChildGuid2, ChildName2 ParentGuid2, ParentName2, ChildGuid3, ChildName3 ParentGuid2, ParentName2, ChildGuid4, ChildName4
I defined a Child class and a parent class that includes a List<Child>
property called Children.
Is it possible to use linq to create objects with a single instance of the Parent class on a graph for a unique ParentGuid, referring to a list filled with children associated with this parent.
Something along the lines of this (note that this code does not compile):
myFlattenedHierarchy.Select(p => new Parent {Guid = p.ParentGuid, Name = p.ParentName, Children = myFlattenedHierarchy.Where(c => c.ParentGuid == p.ParentGuid).Select(c => new Child{Guid = c.ChildGuid, Name = c.ChildName}) });
source share