title: How to represent a filesystem in EF6
body: <p>I need to represent a filesystem using EntityFramework 6. I have tried multiple ways of defining the relationships but I didn't found a way that worked.</p>
  
  <p>So basically I have these 3 classes. (I only included the relevant properties)</p>
  
  <p>Computer.cs</p>
  
  <pre><code>public class Computer
  {
   public FileSystem FileSystem {get; set;}
  }
  </code></pre>
  
  <p>FileSystem.cs</p>
  
  <pre><code>public class FileSystem
  {
   public File RootFile {get; set; }
  }
  </code></pre>
  
  <p>File.cs</p>
  
  <pre><code>public class File
  {
   [Key]
   public int Id {get; set; }
  
   public FileSystem FileSystem {get; set; }
  
   public File Parent { get; set; }
  
   public List&lt;File&gt; children {get; set; }
  }
  </code></pre>
  
  <p>How would I define the relationships of all this ?</p>
  
  <p>I'm not really good at this as this is my first time doing something like that but I think there is:</p>
  
  <ul>
  <li>A One to Many relationship between a File and its children</li>
  <li>A Many to One relationship between a File and its FileSystem</li>
  </ul>
  
  <p>thanks in advance.</p>