title: EF one to one relation change entity with another (substitute)
body: <p>I have problem to change entity one to one with another:</p>
  
  <p>Here is my test classes:</p>
  
  <pre><code>public class MyUser
  {
      public Guid Id { get; set; }
      public string Name { get; set; }
      public virtual MyAddress MyAddress { get; set; }
  }
  
  public class MyAddress
  {
      public Guid Id { get; set; }
      public string AddressLine { get; set; }
      public virtual MyUser MyUser { get; set; }
  }
  </code></pre>
  
  <p>Here is my mapping:</p>
  
  <pre><code>modelBuilder.Entity&lt;MyAddress&gt;().HasOptional(x =&gt; x.MyUser).WithRequired(x =&gt; x.MyAddress);
  </code></pre>
  
  <p>In DB i have</p>
  
  <pre><code>MyUser ID = "abc", Name = "Test"
  MyAddress ID = "abc", AddressLine = "TestAddress"
  MyAddress ID = "dfg", AddressLine = "TestAddress2"
  </code></pre>
  
  <p>No I want to remove from MyAddress from MyUser where they have same ID, and to add to MyUser a MyAddress that has other ID</p>
  
  <pre><code>// myUser.Id = "abc" myUser.MyAddress.Id = "abc"
  // myOldAddress.Id = "abc" myOldAddress.MyUser.Id = "abc"
  // myNewAddress.Id = "dfg" myNewAddress.MyUser = null
  var myUser = repoUser.GetById("abc")
  var myOldAddress = repoAddress.GetById("abc");
  myOldAddress.MyUser = null;
  var myNewAddress = repoAddress.GetById("dfg");
  myUser.MyAddress = myNewAddress;
  myNewAddress.MyUser = myUser;
  //on save I have this exception and what result i want to have
  // myUser.Id = "abc" myUser.MyAddress.Id = "abc"
  // myOldAddress.Id = "hjk" myOldAddress.MyUser = null
  // myNewAddress.Id = "abc" myNewAddress.MyUser.Id = "abc"
  // something like this (substitute)
  
  Exception:
  Additional information: A referential integrity constraint violation occurred: 
  A primary key property that is a part of referential integrity constraint cannot be 
  changed when the dependent object is Unchanged unless it is being set to the
   association's principal object. The principal object must be tracked and not
   marked for deletion.
  
  {"A referential integrity constraint violation occurred: A primary key property
   that is a part of referential integrity constraint cannot be changed when the 
  dependent object is Unchanged unless it is being set to the association's 
  principal object. The principal object must be tracked and not marked for deletion."}
  </code></pre>
  
  <p>Why EF doesn't change ID automatically to be the same as UserId? User must have Address 1:1, but Address has optional User 1:0</p>