title: Entity Framework Core zero-or-one to zero-or-one relation
body: <p>Given these classes:</p>
  
  <pre><code>public class A
  {
      public int Id {get; set;}
      public int? BId {get; set;}
      public B B {get; set;}
  }
  
  public class B
  {
      public int Id {get; set;}
      public int? AId {get; set;}
      public A A {get; set;} 
  }
  </code></pre>
  
  <p>Then with Fluent API</p>
  
  <pre><code> modelBuilder.Entity&lt;A&gt;()
                  .HasOne(a =&gt; a.B)
                  .WithOne(b =&gt; b.A)
                  .HasForeignKey&lt;A&gt;(a =&gt; a.BId);
  </code></pre>
  
  <p>When creating objects and add them to database, things look like following in the corresponding tables:</p>
  
  <ul>
  <li>[A].BId is set </li>
  <li>[B].AId = null</li>
  </ul>
  
  <p>When I retrieve data using EF Core:</p>
  
  <ul>
  <li>A.B is set, A.BId is set</li>
  <li>B.A is set, but <strong>B.AId is null</strong>. </li>
  </ul>
  
  <p>What should I do to have B.AId set as well?</p>