title: Self-referencing table with parent-child relationship to represent file tree using LINQ
body: <p>I have a single database table representing a file tree structure.</p>
  
  <pre><code>Files
  - Id (int, primary key)
  - Name
  - ParentId (int, foreign key to Files.Id)
  </code></pre>
  
  <p>How can I write a method that makes sure all parents of a child cannot have the child's Id as its ParentId to prevent a infinite loop when displaying the tree structure.</p>
  
  <p>Also, is there a more efficient way to design this?</p>
  
  <p>Update:
  I use sql server 2008 which supports hierarchy id, would that be helpful? (I'm not sure if EF supports it)</p>