Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple foreign keys pointing to same table in Entity Framework 4.1 code first
    primarykey
    data
    text
    <p>I'm stuck at trying to write the Entity Framework 4.1 code first model for the following DB relationship.</p> <p>Here is a visual of the relationship.<img src="https://i.stack.imgur.com/zlzef.png" alt="enter image description here"></p> <p>dbo.[Companies] can have either Seller or Debtor as Company Types.</p> <p>dbo.[SellerDebtors] defines the connection a Seller Company has with a Debtor Company.</p> <p>The code i've written is based on my original EF 4.0 POCO model code. This is what I've come up with - This code does not work. </p> <pre><code>public class SellerDebtor { public int SellerDebtorId { get; set; } public int DebtorCompanyId { get; set; } public int SellerCompanyId { get; set; } public Company DebtorCompany { get; set; } public Company SellerCompany { get; set; } public ICollection&lt;SellerDebtorInfo&gt; SellerDebtorInfos { get; set; } public ICollection&lt;SellerDebtorFile&gt; SellerDebtorFiles { get; set; } } public class Company { public int CompanyId { get; set; } public string CompanyType { get; set; } public string Name { get; set; } public virtual ICollection&lt;User&gt; Users { get; set; } public virtual ICollection&lt;CompanyInfo&gt; CompanyInfos { get; set; } public virtual ICollection&lt;CompanyFile&gt; CompanyFiles { get; set; } public virtual ICollection&lt;SellerDebtor&gt; SellerDebtorDebtorCompanies { get; set; } public virtual ICollection&lt;SellerDebtor&gt; SellerDebtorSellerCompanies { get; set; } } </code></pre> <p>At the moment, I'm getting this as an error:</p> <pre><code>System.Data.SqlClient.SqlException: Invalid column name 'DebtorCompany_CompanyId'. Invalid column name 'SellerCompany_CompanyId'. Invalid column name 'Company_CompanyId'. Invalid column name 'Company_CompanyId1'. </code></pre> <p>Ideally, I'd like to be able to maintain the naming of the relationships.</p> <p>I'm guessing i need to set some attributes but i'm not sure what to set. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload