title: EF many-to-many with composite key only gets one left and one right key on the join table
body: <p>I have this model that has a composite key made from 3 different keys.  When it creates a many-to-many join table <code>DomainGroupDomainGroup</code>, I get only two keys.  One left, one right.  It references the field <code>Key</code>, which is really just a <code>ToLower()</code> of the distinguished name.  The only problem is there could be many <code>Domains</code> or <code>DomainScans</code> which would create collisions in primary keys, so we need both the <code>DomainscanId</code> and the <code>DomainId</code> to even identify which row we're actually talking about.  Not to mention, I doubt it would even let me collide without an error.</p>
  
  <pre><code>CREATE TABLE [dbo].[DomainGroupDomainGroup] (
      [DomainGroup_Key]  NVARCHAR (128) NOT NULL,
      [DomainGroup_Key1] NVARCHAR (128) NOT NULL,
      CONSTRAINT [PK_dbo.DomainGroupDomainGroup] PRIMARY KEY CLUSTERED ([DomainGroup_Key] ASC, [DomainGroup_Key1] ASC),
      CONSTRAINT [FK_dbo.DomainGroupDomainGroup_dbo.DomainGroup_DomainGroup_Key] FOREIGN KEY ([DomainGroup_Key]) REFERENCES [dbo].[DomainGroup] ([Key]),
      CONSTRAINT [FK_dbo.DomainGroupDomainGroup_dbo.DomainGroup_DomainGroup_Key1] FOREIGN KEY ([DomainGroup_Key1]) REFERENCES [dbo].[DomainGroup] ([Key])
  );
  </code></pre>
  
  <p>Here's the model:</p>
  
  <pre><code>using System.Collections.Generic;
  using System.ComponentModel.DataAnnotations;
  using System.ComponentModel.DataAnnotations.Schema;
  
  namespace Server.DomainTools.Controller.Domain.Model
  {
      public class DomainGroup
      {
  
          public virtual ICollection&lt;DomainUser&gt; DomainUsers { get; set; }
          public virtual ICollection&lt;DomainGroup&gt; DomainGroups { get; set; }
          public virtual ICollection&lt;DomainGroup&gt; Parents { get; set; }
          public string Name { get; set; }
          public string DistinguishedName { get; set; }
  
          [ForeignKey("DomainScan")]
          public int DomainScanId { get; set; }
  
          [ForeignKey("Domain")]
          public int DomainId { get; set; }
  
          //Composite primary key
          //DomainScanId is the version
          [Key, Column(Order = 0)]
          public string Key { get; set; }
  
          [Key, Column(Order = 1)]
          public DomainScan DomainScan { get; set; }
  
          [Key, Column(Order = 2)]
          public Domain Domain { get; set; }
  
      }
  }
  </code></pre>