title: Tree structure to get parent node and its children
body: <p>Please find the table  structure below:</p>
  
  <pre><code>Folderid                    parentFolderid              Guid
  1                           0                           1234
  2                           1                           5678
  3                           2                           9012
  4                           3                           87697
  5                           7                           4443 
  </code></pre>
  
  <p>The requirement is if I pass folderId the function has to give me all the guids.</p>
  
  <p>For example:If I pass <code>1</code> to the function, I should get first four Guids(parent and its children).
  I have a function which returns all the guids as follows:</p>
  
  <pre><code>public List&lt;Guid&gt; Folders(int folderId)
  { 
      // To get the folderids based on parentfolderid
      var a = entity.Where(x =&gt; x.parentfolderId == folderId).FirstOrDefault();
       return a;
  
  }
  </code></pre>
  
  <p>I am able to get only up to one level of ids.</p>
  
  <p>Is there any way to get parent, its children, grandchildren till the leaf?</p>