title: Unable to determine a valid ordering for dependent operations?
body: <p>I have this model:</p>
  
  <pre><code>public class ContentType
  {
      public int ContentTypeId{get;set;}
      public string Name{get;set;}
      public Lang Lang{get;set;}
      public bool IsPublished{get;set;}
      public int? ParentId { get; set; }
      public int UserId { get; set; }
      public virtual User User { get; set; }
      public virtual ContentType Parent { get; set; }
      public virtual List&lt;ContentType&gt; Children { get; set; }
  }
  </code></pre>
  
  <p>It has a one to many relation to itself.</p>
  
  <p>And in Context I have this:</p>
  
  <pre><code>protected override void OnModelCreating(DbModelBuilder modelBuilder)
  {
      modelBuilder.Entity&lt;ContentType&gt;().HasMany(c =&gt; c.Children).WithOptional(c =&gt; c.Parent).HasForeignKey(c =&gt; c.ParentId);
      base.OnModelCreating(modelBuilder);
      modelBuilder.Conventions.Remove&lt;PluralizingTableNameConvention&gt;();    
  }
  </code></pre>
  
  <p>But when I am saving a record with <code>ParentId=0</code> I see this error:</p>
  
  <blockquote>
    <p>Unable to determine a valid ordering for dependent operations.
    Dependencies may exist due to foreign key constraints, model
    requirements, or store-generated values.</p>
  </blockquote>
  
  <p>Note that the relation in database is not exist because of the following error:</p>
  
  <blockquote>
    <p>'ContentType' table
    - Unable to create relationship 'FK_ContentType_ContentType'.   The ALTER TABLE statement conflicted with the FOREIGN KEY SAME TABLE
    constraint "FK_ContentType_ContentType". The conflict occurred in
    database "CMS", table "dbo.ContentType", column 'ContentTypeId'.</p>
  </blockquote>
  
  <p>But I don't think the problem be from here.I don't know.</p>
  
  <p>What is it wrong here?</p>