У меня есть класс следующим образом:
public class Item
{
public int ItemID { get; set; }
public int GroupLevel { get; set; }
public string ItemName { get; set; }
public string ItemDesc { get; set; }
}
Это возвращает плоский результат IEnumerable, но мне нужно сгруппировать их в отношения Parent -> Child -> Grand-child, основанные на GroupLevel и ItemID.Вот как выглядят текущие данные:
ItemID: 1
GroupLevel: 1
ItemName: All Groups
ItemDesc: Item 1 description
ParentID: null
ItemID: 2
GroupLevel: 2
ItemName: Boulder
ItemDesc: Boulder description
ParentID: 1
ItemID: 3
GroupLevel: 2
ItemName: Atlanta
ItemDesc: Atlanta description
ParentID: 1
ItemID: 4
GroupLevel: 3
ItemName: Boulder - Boulder south
ItemDesc: Grand-child of Boulder (ID: 2)
ParentID: 2
ItemID: 5
GroupLevel: 3
ItemName: Boulder - Boulder North
ItemDesc: Another grand-child of Boulder (ID: 2)
ParentID: 2
ItemID: 6
GroupLevel: 3
ItemName: Atlanta - West
ItemDesc: Grand-child of Atlanta (ID: 3)
ParentID: 3
Я бы хотел структурировать данные следующим образом:
ItemID: 1
GroupLevel: 1
ItemName: All Groups
ItemDesc: Item 1 description
ParentID: null
ItemID: 2
GroupLevel: 2
ItemName: Boulder
ItemDesc: Boulder description
ParentID: 1
ItemID: 4
GroupLevel: 3
ItemName: Boulder - Boulder south
ItemDesc: Grand-child of Boulder (ID: 2)
ParentID: 2
ItemID: 5
GroupLevel: 3
ItemName: Boulder - Boulder North
ItemDesc: Another grand-child of Boulder (ID: 2)
ParentID: 2
ItemID: 3
GroupLevel: 2
ItemName: Atlanta
ItemDesc: Atlanta description
ParentID: 1
ItemID: 6
GroupLevel: 3
ItemName: Atlanta - West
ItemDesc: Grand-child of Atlanta (ID: 3)
ParentID: 3
Есть предложения?Спасибо.