title: EF : How do I convert from Independent Association to Foreign Key Association without changing schema or losing data
body: <p>I have two models that have a bi-directional 0-to-one relationship.</p>
  
  <p>A, B. A may have a B. B may have an A. </p>
  
  <p>Currently these are set up with navigational properties within each class, WITHOUT foreign key properties (set using fluent syntax)</p>
  
  <pre><code>public class A{
  [key]
  public int Id {get;set;}
  public B B {get;set;}}
  
  public class B{
  [key]
  public int Id {get;set;}
  A A {get;set;}
  }
  
       modelBuilder.Entity&lt;B&gt;()
              .HasOptional(b =&gt; b.A)
              .WithOptionalPrincipal()
              .Map(b =&gt; b.MapKey("AId"));
  
          modelBuilder.Entity&lt;A&gt;()
              .HasOptional(p =&gt; p.B)
              .WithOptionalPrincipal()
              .Map(p =&gt; p.MapKey("BId"));
  </code></pre>
  
  <p>So far things are working fine, as expected.</p>
  
  <p>I would now like to expose these ID properties in my entities, so that to aid in updating disconnected entity relationships. </p>
  
  <p>When I just add the properties, I get "duplicate name" errors per <a href="https://stackoverflow.com/questions/7641027/error-0019-each-property-name-in-a-type-must-be-unique-on-id-field">error 0019: Each property name in a type must be unique on ID field</a></p>
  
  <p>If I remove the maps, and then try to use the keys, it appears to work, but the migration decides to drop the FK columns, and then re-add them with a different name. This will break all my existing data.</p>
  
  <p>I tried to rewrite the fluent mapping to use HasMany().HasForeignKey(), but that didn't work either. (Even though its not really many, that seems to be required to get the HasForeignKey method?)</p>
  
  <p>What is the right way to upgrade this relationship while keeping the schema the same to preserve existing data in the database?</p>