title: How to return both parent and child using LINQ against 1 table
body: <p>Been looking for a solution for this but haven't been able to find one so far.</p>
  
  <p>I'm fairly sure its possible with one linq call but having trouble working it out.</p>
  
  <p>I have the following data structure</p>
  
  <pre><code>Id      ParentId     Name       ValidFlag
  
  1       NULL         parent 1   1
  2       NULL         parent 2   1
  3       NULL         parent 3   0
  4       1            child 1    1
  5       1            child 2    1
  6       2            child 3    1
  7       2            child 4    1
  8       3            child 5    1
  9       3            child 6    1
  </code></pre>
  
  <p>Now what i want to do is return all valid parents and their children so this case i would return everything except Id = 3 (parent 3).</p>
  
  <p>Is there a simple way to do this with LINQ? Im guessing there is but my LinqIQ is very limited, i know the basics but beyond that i need much help.</p>
  
  <p>Is this a case for ToLookup() or Union or neither?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>To be more specific as I've failed to do so, both types of records are in the same table, i want to return all records whether its a parent or child in the 1 query if possible. </p>
  
  <p>Its not as simple as just selecting all records where ValidFlag = 1. The source database is a mess and the only way to get all records is to find the "valid" parents then find all children for the "valid" parents. I know i can just do a simple query to return all valid parent records then do a separate query to find all child of those parents, but combining into 1 LINQ query is where i fail, i was hoping that is possible.  In this case it is possible that there are valid child entries of invalid parents, hence need for the question</p>