title: Using LINQ to select hierarchical data?
body: <p>I have a table in SQL Server that is structured like this:</p>
  
  <pre><code>id  Name  Parent
  --  ----  ------
  1   foo   null
  2   bar   1
  3   oof   null
  4   rab   3
  .
  .
  .
  </code></pre>
  
  <p>I need to get the data from the two associated rows as one row in a .NET DataTable .  My desired DataTable would look like this:</p>
  
  <pre><code>Parent  Child
  ------  -----
  foo     bar
  oof     rab
  </code></pre>
  
  <p>I was able to accomplish this using the query below:</p>
  
  <pre><code>with temp as
  (
    SELECT 1 id,'foo' name, null parent
    UNION
    select 2,'bar', 1
    UNION
    SELECT 3,'oof', null
    UNION
    select 4,'rab', 3
  )
  
  SELECT t1.name parent, t2.name child
  FROM temp t1
  INNER JOIN temp t2
  ON t1.id = t2.parent
  </code></pre>
  
  <p>But I am curious if there is an easy way to do this using LINQ?  (our shop uses LINQ for most database access) </p>