title: Code first Unable to determine a valid ordering for dependent operations
body: <p>I am using EF Code First database. Here I have an Entity "Relatie" that has a Parent ID (MoederRid) which is nullable. When we create the database we create a default Relation where the Parent is itself, this is a business rule. When we try to save the changes we get: </p>
  
  <pre><code>"Unable to determine a valid ordering for dependent operations. Dependencies may exist due to foreign key constraints, model requirements, or store-generated values."
  </code></pre>
  
  <p>We have been searching google but no answers found. Anyone have a clue?</p>
  
  <p>Class:</p>
  
  <pre><code>  public partial class Relatie : CreateAT
  {
      public Relatie()
      {
          Gebruikers = new HashSet&lt;Gebruiker&gt;();
          Contactpersonen = new HashSet&lt;Contactpersoon&gt;();
          RelatieBestanden = new HashSet&lt;Relatie_Bestand&gt;();
      }
  
      public int ID { get; set; }
  
      public int GeslachtEnumID { get; set; }
  
      public virtual EnumATCode GeslachtEnum { get; set; }
  
      public string Naam { get; set; }
      public int? MoederRID { get; set; }
  
      [ForeignKey("MoederRID")]
      public virtual Relatie Moeder { get; set; }
  }
  </code></pre>
  
  <p>Adding on Configuration:</p>
  
  <pre><code>private void AddRootRelatie(FrameworkModel context)
      {
          //Add a root relatie. All relations are a member under the root
          var relatie = context.Relaties.SingleOrDefault(m =&gt; m.PublicID == FrameworkModel.ROOT_RELATIE_GUID);
          if (relatie == null)
          {
              relatie = new Relatie()
              {
                  PublicID = FrameworkModel.ROOT_RELATIE_GUID,
                  Naam = "Root",
                  GeslachtEnumID = (int)GeslachtEnum.O
              };
              relatie.Moeder = relatie;
              context.Relaties.Add(relatie);
          }
      }
  </code></pre>
  
  <p>I have tried some of the optioned in: <a href="https://stackoverflow.com/questions/6090283/how-to-insert-row-in-table-with-foreign-key-to-itself">How to insert row in table with foreign key to itself?</a> But unfortunately did not do the trick for me. </p>