title: Hierarchy from Flat Data
body: <p>I have an employee class that has an employeeId (int), parent(int) and children property <code>List&lt;Employee&gt;</code>. I get the employee list from the database in the correct order <strong>and now need to build the hierarchy</strong>, but I am failing miserably...I know this is programming 101, but I am having a hard time with it.</p>
  
  <pre><code>public class Employee
  {
    public int EmployeeId { get; set;}
    public int ParentId;{ get; set;}
    public List&lt;Employee&gt; Children; { get; set;}
  
  }
  </code></pre>
  
  <p>Data Example</p>
  
  <pre><code>EmployeeId, ManagerId
  1, 0 //no one
  2, 1
  3, 1
  4, 2
  5, 2
  6, 3
  7, 3
  </code></pre>