title: EF Code First - How do I code OnModelCreating with an entity that has property which is collection of itself?
body: <p>I have an entity that has a property which is a collection of it's self.  How do I program my classes and the OnModelCreating to correctly create the database tables?</p>
  
  <pre><code>public class Category{
    public int Id { get; set; }
    public string Name { get; set; }
    public ICollection&lt;Category&gt; PriorCategories { get; set; }
  }
  </code></pre>
  
  <p>So, for the end result, I want my database mapping table (PriorCategories) to look like this:</p>
  
  <p>Id - PK
  ParentCategoryId - FK to Category table
  ChildCategoryId - FK to Category table</p>
  
  <p>How do I set up my classes and/or program the overridden OnModelCreating function?</p>
  
  <p>Thanks!</p>