title: EF 4.1 Multiple Many to Many relationships in single class
body: <p>I have a class with multiple many to many relationships mapping to the same secondary class. My EquipmentSet class has two arrays of Equipment objects, and the Equipment class also has an array of EquipmentSets to determine which sets the equipment is a part of. </p>
  
  <p>EF is only generating a lookup table for the second Many to Many relationship. How can I tell EF to generate lookup tables for both?  When the code below is used, only the table "ModelSpecificEquipment" is generated.  The table "GlobalEquipment" never gets generated.</p>
  
  <pre><code>public partial class EquipmentSet 
  {
      public int Id { get; set; }
      public List&lt;Equipment&gt; Global { get; protected set; }
      public List&lt;Equipment&gt; ModelSpecific { get; protected set; }
  
      public EquipmentSet()
      {
          Global = new List&lt;Equipment&gt;();
          ModelSpecific = new List&lt;Equipment&gt;();
      }
  }
  
  
  public partial class Equipment
  {
      public int Id { get; set; }
      public List&lt;EquipmentSet&gt; EquipmentSets { get; set; }
  
      public Equipment()
      {
      }
  }
  
  
  
  public class DataContext : DbContext
  {
      public DbSet&lt;Equipment&gt;  Equipment { get; set; }
  
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          modelBuilder.Entity&lt;Equipment&gt;()
              .HasMany&lt;EquipmentSet&gt;(x =&gt; x.EquipmentSets)
              .WithMany(x =&gt; x.Global)
              .Map(x =&gt;
              {
                  x.MapLeftKey("EquipmentId");
                  x.MapRightKey("EquipmentSetId");
                  x.ToTable("GlobalEquipment");
              });
  
          modelBuilder.Entity&lt;Equipment&gt;()
              .HasMany&lt;EquipmentSet&gt;(x =&gt; x.EquipmentSets)
              .WithMany(x =&gt; x.ModelSpecific)
              .Map(x =&gt;
              {
                  x.MapLeftKey("EquipmentId");
                  x.MapRightKey("EquipmentSetId");
                  x.ToTable("ModelSpecificEquipment");
              });
          base.OnModelCreating(modelBuilder);
      }
  }
  </code></pre>
  
  <p>Again, at this point the database that EF creates only contains 3 tables: EquipmentSets, Equipments, ModelSpecificEquipments.  GlobalEquipments is missing.</p>