title: Two identical foreign keys on Entity Framework
body: <p>I have these tables:</p>
  
  <p><code>Companies (CompanyID, Name, CompanyTypeID)</code><br />
  <code>CompanyTypes (CompanyTypeID, Name)</code><br /></p>
  
  <p>I want to avoid tables like "TypeACompanies", "TypeBCompanies", etc. But the issue is that there is a many-to-many relationship between two particular company types - one "Retailer" company can have many "Supplier" companies, and one "Supplier" company can supply many "Retailer" companies.</p>
  
  <p>This led to a new linking table with a composite primary key - both fields being foreign keys to <code>Companies</code>:</p>
  
  <p><code>RetailerCompanies_SupplierCompanies (RetailerCompanyID, SupplierCompanyID)</code><br /></p>
  
  <p>Sample data of the linking table:<br />
  <strong>(1, 1)<br />
  (1, 2)<br />
  (1, 3)<br />
  (2, 1)<br />
  (2, 2)<br />
  (2, 3)<br /></strong></p>
  
  <p>In Entity Framework the <code>Company</code> entity look like this (I'm doing Database First):</p>
  
  <pre><code>public Company()
  {
      this.Companies1 = new HashSet&lt;Company&gt;();
      this.Companies = new HashSet&lt;Company&gt;();
  }
  </code></pre>
  
  <p>Is this bad practice? Is there a better way to achieve this relationship?</p>