Hierarchy from Flat Data

前端 未结 3 719
闹比i
闹比i 2021-01-03 16:38

I have an employee class that has an employeeId (int), parent(int) and children property List. I get the employee list from the database in the

3条回答
  •  悲哀的现实
    2021-01-03 17:32

    List allEmployees = new List();
    allEmployees.AddRange(LoadAllEmployees()); // pull from DB in flat format    
    foreach (var employee in allEmployees)
    {
      employee.Children = allEmployees.Where(e => e.ParentId == employee.EmployeeId).ToList();
    }
    

提交回复
热议问题