title: Recursive Linq - Parent indication for child property?
body: <p>I have a table (let's say DataTable for this example) which has hierarchy records ( id,ParentId,IsEmergency) : </p>
  
  <p><img src="https://i.stack.imgur.com/yqWXl.png" alt="enter image description here"></p>
  
  <p><code>ParentId=0</code> means root.</p>
  
  <p>So we have this : </p>
  
  <pre><code>0
  |
  +--- 4706606
  |
  +--- 4706605
  |
  +--- 4666762
          |
          +--- 4668461
                 |
                 +--- 4706607 
  </code></pre>
  
  <p>I'm after displaying only the those records who has <code>parentId=0</code> </p>
  
  <p>But I want to add another logical column which states "this parent has <code>IsEmergency=true</code> in one of it's childs/sub childs</p>
  
  <p>So I'm after </p>
  
  <pre><code>id         parentId        hasEmergencyInOneOfItsChild
  -------------------------------------------------------
  4706606    0                false
  4706605    0                false
  4666762    0                true
  </code></pre>
  
  <p><strong>Question:</strong></p>
  
  <p>How can I achieve it via recursive linq ?</p>
  
  <p>For   convenience I created this Datatable :</p>
  
  <pre><code>   DataTable dt = new DataTable("myTable");
     dt.Columns.Add("id", typeof (int));
     dt.Columns.Add("parentId", typeof (int));
     dt.Columns.Add("isEmergency", typeof (bool));
  
     DataRow row = dt.NewRow();
     row["id"] =4706606;
     row["parentId"] = 0;
     row["isEmergency"] =false;
     dt.Rows.Add(row);
  
         row = dt.NewRow();
     row["id"] =4706605;
     row["parentId"] = 0;
     row["isEmergency"] = false;
     dt.Rows.Add(row);
  
         row = dt.NewRow();
     row["id"] =4666762;
     row["parentId"] = 0;
     row["isEmergency"] =false;
     dt.Rows.Add(row);
  
         row = dt.NewRow();
     row["id"] =4668461;
     row["parentId"] = 4666762;
     row["isEmergency"] = false;
     dt.Rows.Add(row);
  
          row = dt.NewRow();
     row["id"] =4706607;
     row["parentId"] = 4668461;
     row["isEmergency"] = true;
     dt.Rows.Add(row);
  </code></pre>
  
  <p><strike>I've tried something but it is pretty nasty and not efficient</strike></p>