title: Entity Framework Optional Relationship causing "conflicting multiplicities"
body: <p>I am using Entity Framework code first for a simple database containing multiple choice questions. Each question has multiple possible answers and specifies one as the correct answer.</p>
  
  <pre><code>public class Question
  {
      public int QuestionId { get; set; }
  
      [ForeignKey("CorrectAnswer")]
      public int CorrectAnswerId { get; set; }
      public string Text { get; set; }
  
      public virtual ICollection&lt;Answer&gt; Answers { get; set; }
  
      public virtual Answer CorrectAnswer { get; set; }
  }
  
  public class Answer
  {
      public int AnswerId { get; set; }
      [ForeignKey("Question")]
      public int QuestionId { get; set; }
      public string Text { get; set; }
  
      public virtual Question Question { get; set; }
  }
  
  protected override void OnModelCreating(DbModelBuilder modelBuilder)
  {
      modelBuilder.Entity&lt;Answer&gt;()
          .HasRequired(a =&gt; a.Question)
          .WithMany(q =&gt; q.Answers)
          .HasForeignKey(a =&gt; a.QuestionId)
          .WillCascadeOnDelete(false);
  }
  </code></pre>
  
  <p>This all works fine, but I need to avoid the catch 22 situation where you can't create a question because it needs a correct answer, but you can't create an answer because it needs a question. So I want to make the CorrectAnswerId field nullable, allowing you to create the question, then the answers, and then specify the correct answer.</p>
  
  <p>I've tried variations on the following, but always get a "conflicting multiplicities" exception:</p>
  
  <pre><code>modelBuilder.Entity&lt;Question&gt;()
              .HasOptional(q =&gt; q.CorrectAnswer)
              .WithRequired(a =&gt; a.Question)
              .Map(p =&gt; p.MapKey("CorrectAnswerId"));
  </code></pre>