I have an object which looks like this:
Tree {
String Name;
Int ID;
List<SubObjects> SubObjects
}
SubObjects {
int Level;
string Name;
}
I have information coming over in the following form of List<Output>
where Output
is:
Output {
String TreeName;
Int TreeID;
Int SubObjectLevel;
String SubObjectName;
}
Essentially, the Tree is represented in following format
Tree1 TreeID1 Level1 SubObject1
Tree1 TreeID1 Level2 SubObject2
Tree1 TreeID1 Level3 SubObject3
Tree1 TreeID1 Level1 SubObject4
I want to write a LINQ query to populate Tree and I am stuck at GroupBy. It is a very basic question but I am in process of learning LINQ, any help will be much appreciated.
Thanks!
EDIT:
Here is my code so far
var trees =
from o in output
select new Tree {
Name = o.TreeName,
ID = o.TreeID,
SubObjects = //somehow group them
}
I have also tried
var trees =
from o in output
group o in o.TreeID into levels
select new Tree {
Name = //at this point o.TreeName is not available
}