title: EF Association Tables in multi-tenant DB
body: <p>I have run into a serious limitation of EF and need help.</p>
  <p>Here are my tables:</p>
  <p><strong>Table: Company</strong></p>
  <ul>
  <li>TenantId INT  PK</li>
  <li>CompanyId INT PK</li>
  <li>other columns...</li>
  </ul>
  <p><strong>Table: Role</strong></p>
  <ul>
  <li>TenantId INT PK</li>
  <li>RoleId  INT PK</li>
  <li>other columns...</li>
  </ul>
  <p>Here is the association table:
  <strong>Table:  CompanyRoles</strong></p>
  <ul>
  <li>TenantId  INT  PK</li>
  <li>CompanyId INT  PK</li>
  <li>RoleId INT PK</li>
  </ul>
  <p>This issue I am having is in my mapping class, I'm trying to avoid modeling the association table to keep things simple, everything worked earlier but we added <code>TenantId</code> everywhere.</p>
  <p>Here is the C# mapper code for <code>Company</code>:</p>
  <pre><code>  this.HasMany(t =&gt; t.ContactRoles)
        .WithMany(t =&gt; t.Companies)
        .Map(m =&gt;
        {
          m.ToTable(&quot;CompanyContactRoles&quot;);
          m.MapLeftKey(&quot;TenantId&quot;, &quot;CompanyID&quot;);
          m.MapRightKey(&quot;TenantId&quot;, &quot;RoleID&quot;);
        });
  </code></pre>
  <p>EF blows up because I am using <code>TenantId</code> on both sides of the many to many mapping, here is the error:</p>
  <p>One or more validation errors were detected during model generation:</p>
  <h1>TenantId: Name: Each property name in a type must be unique. Property name 'TenantId' is already defined.</h1>
  <p>Does EF not support multi-column KEYED association tables?  The TenantId in the association table is used for 2 relationships but it seems to want a dedicated TenantId for each relationship, that isn't going to happen as those columns must exist in the actual table.</p>