title: Conflicting changes to the role x of the relationship y have been detected
body: <p>I am having the exception</p>
  <blockquote>
  <p>Conflicting changes to the role x of the relationship y have been detected.</p>
  </blockquote>
  <p>Every time I add my entity to my context</p>
  <pre><code>Database.MyEntitys.Add(MyEntity);
  </code></pre>
  <p>The class MyEntity contain this property :</p>
  <pre><code>public virtual ICollection&lt;DetailInfo&gt; Group { get; set; }
  </code></pre>
  <p>The DetailInfo class is pretty simple:</p>
  <pre><code>public class DetailInfo:BaseEntity {
      public virtual Detail Detail { get; set; }
      public decimal Total { get; set; }
      public virtual MyEntity MyEntity { get; set; }
  }
  </code></pre>
  <p>The DatabaseContext is also simple:</p>
  <pre><code>public class MyEntityConfiguration : EntityTypeConfiguration&lt;MyEntity&gt; {
      public MyEntityConfiguration() {
          HasMany(e =&gt; e.Group).WithRequired(s =&gt; s.MyEntity).WillCascadeOnDelete(true);
      }
  }
  
  public class DetailInfoConfiguration : EntityTypeConfiguration&lt;DetailInfo&gt; {
      public DetailInfoConfiguration() {
          HasRequired(x =&gt; x.MyEntity).WithMany(s =&gt; s.Group);
          HasRequired(x =&gt; x.Detail);
          HasKey(s =&gt; s.ID);
          ToTable(&quot;DetailInfo&quot;);
      }
  }
  </code></pre>
  <p>On the Database side the table MyEntity has a primary key to the column ID. The DetailInfo has also a primary key called ID. DetailInfo contains 2 FK, one to MyEntity and one to Detail which is another entity.</p>
  <p>In the problematic scenario, the MyEntity is new has a new Detail. I am expecting a new entry for MyEntity with a new Detail and having all FK correctly setup.</p>
  <h3>Edit:</h3>
  <p>here is the Insert:</p>
  <pre><code>public virtual int Insert(MyEntity myEntity) {
  
      if (myEntity.Group != null &amp;&amp; myEntity.Group.Count() == 0) {
          myEntity.Group = null; 
      }
  
      if (myEntity.Group != null) {
          foreach (var g in myEntity.Group)
          {
           if (g.PropertyOneToOne != null) {
                  if (g.PropertyOneToOne.ID == 0) {
                      myEntity.PropertyOneToOne = null;
                  }
                  else {
                      if (!Database.PropertyOneToOnes.Local.Any(e =&gt; e.ID == g.PropertyOneToOne.ID)) {
                          Database.PropertyOneToOnes.Attach(g.PropertyOneToOne);
                      }
                      myEntity.PropertyOneToOne = Database.PropertyOneToOnes.Local.Single(e =&gt; e.ID == g.PropertyOneToOne.ID);
                  }
              }
              else {
                  myEntity.PropertyOneToOne = null;
              }
          }
      }
      Database.MyEntitys.Add(myEntity);
  }
  </code></pre>