title: Many to many primary key
body: <p>Class:</p>
  
  <pre><code>public class BranchAds
  {
      [Key, Column(Order = 0)]
      [ForeignKey("branch")]
      public int branch_id { get; set; }
      [Key, Column(Order = 1)]
      [ForeignKey("ad")]
      public int advertisement_id { get; set; }
  
      [JsonIgnore]
      public virtual Branch branch { get; set; }
      public virtual Advertisement ad { get; set; }
  
      [JsonProperty("start_time")]
      public DateTime start_time { get; set; }
  
      [JsonProperty("end_time")]
      public DateTime end_time { get; set; }
  
      public DateTime date { get; set; }
  
  }
  </code></pre>
  
  <p>This error:</p>
  
  <blockquote>
    <p>Violation of PRIMARY KEY constraint 'PK_dbo.BranchAds'. Cannot insert duplicate key in object 'dbo.BranchAds'. The duplicate key value is (1, 26).  </p>
  </blockquote>
  
  <p>Happens when I try to insert another BranchAds using the same keys.. Well I should since theoretically this is a many to many (junction) table. However the database seems unaware of this.</p>
  
  <p>Why am I doing it this way? Because I need custom fields in the many to many table.</p>
  
  <p>What can I do to resolve this? Without adding a <code>[Key]</code> to the BranchAds class.</p>