title: One to one relationship with nullable foreign key in Entity Framework
body: <p>I'm trying to create database relationship between two tables.</p>
  
  <p>I have redemption codes which can be free. But one user has only one redem code.</p>
  
  <p>I created two entities:</p>
  
  <pre><code>public class UserProfile
  {
      [Key]
      [ForeignKey("User")]
      public int Id { get; set; }
  
      //... other fields
  
      public virtual RedemptionCode RedemptionCode { get; set; }
  
      public virtual User User { get; set; }
  }
  
  public class RedemptionCode
  {
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int Id { get; set; }
  
      [ForeignKey("UserProfile")]
      public int? UserProfileId { get; set; }
      public virtual UserProfile UserProfile { get; set; }
  
      [Required]
      public string Code { get; set; }
  }
  </code></pre>
  
  <p>But when I adding a migration I have the following error:</p>
  
  <blockquote>
    <p>One or more validation errors were detected during model generation:</p>
    
    <p>RedemptionCode_UserProfile_Source: : Multiplicity is not valid in Role 'RedemptionCode_UserProfile_Source' in relationship 'RedemptionCode_UserProfile'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be '*'.</p>
  </blockquote>
  
  <p>What do I really want? I want to store free redem codes in db and link one of them with new user in my system.</p>