title: Use a Multi-Column (Composite) Primary Key that includes a Foreign Key Relationship
body: <p>I'm using Entity Framework 4.3 with a simple design:</p>
  
  <pre><code>public class Post
  {
      [Key]
      public int ID { get; set; }
  
      public string Text { get; set; }
  
      public HashSet&lt;PostTag&gt; Tags { get; set; }
  }
  
  public class PostTag
  {
      public Post Post { get; set; }
  
      [Key, Column(Order=0)]
      [ForeignKey("Post")]
      public int PostID { get; set; }
  
      [Key, Column(Order=1)]
      [MaxLength(50)]
      public string Tag { get; set; }
  }
  </code></pre>
  
  <p>So you can see a Post has multiple tags, and those tags use a composite primary key of both the PostID and the Tag.</p>
  
  <p>When I run <code>update-database</code> I get:</p>
  
  <pre><code>Cannot define PRIMARY KEY constraint on nullable column in table 'PostTag'.
  </code></pre>
  
  <p>I've tried applying the [Required] attribute to both Post and PostID. I've tried placing the ForeignKey attribute on the other side of the FK relationship. I've tried applying the InverseProperty attribute to Post (which changes the error to just a vague NullReferenceException - this seems like a bug).</p>