title: One to one optional relationship using Entity Framework Fluent API
body: <p>We want to use one to one optional relationship using Entity Framework Code First. We have two entities.</p>
  
  <pre><code>public class PIIUser
  {
      public int Id { get; set; }
  
      public int? LoyaltyUserDetailId { get; set; }
      public LoyaltyUserDetail LoyaltyUserDetail { get; set; }
  }
  
  public class LoyaltyUserDetail
  {
      public int Id { get; set; }
      public double? AvailablePoints { get; set; }
  
      public int PIIUserId { get; set; }
      public PIIUser PIIUser { get; set; }
  }
  </code></pre>
  
  <p><code>PIIUser</code> may have a <code>LoyaltyUserDetail</code> but <code>LoyaltyUserDetail</code> must have a <code>PIIUser</code>.
  We tried these fluent approach techniques.</p>
  
  <pre><code>modelBuilder.Entity&lt;PIIUser&gt;()
              .HasOptional(t =&gt; t.LoyaltyUserDetail)
              .WithOptionalPrincipal(t =&gt; t.PIIUser)
              .WillCascadeOnDelete(true);
  </code></pre>
  
  <p>This approach didn't create <code>LoyaltyUserDetailId</code> foreign key in <code>PIIUsers</code> table.</p>
  
  <p>After that we tried the following code.</p>
  
  <pre><code>modelBuilder.Entity&lt;LoyaltyUserDetail&gt;()
              .HasRequired(t =&gt; t.PIIUser)
              .WithRequiredDependent(t =&gt; t.LoyaltyUserDetail);
  </code></pre>
  
  <p>But this time EF didn't create any foreign keys in these 2 tables.</p>
  
  <p>Do you have any ideas for this issue?
  How can we create one to one optional relationship using entity framework fluent api?</p>