我卡在了尝试编写Entity Framework 4.1的Code First模型上,涉及以下数据库关系。
以下是关系的可视化图形:
dbo.[Companies]可以有卖方(Seller)或债务人(Debtor)作为公司类型。
dbo.[SellerDebtors]定义了卖方公司与债务人公司之间的连接。
我编写的代码基于原始的EF 4.0 POCO模型代码。这就是我想出的 - 这段代码无效。
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<SellerDebtorInfo> SellerDebtorInfos { get; set; }
public ICollection<SellerDebtorFile> SellerDebtorFiles { get; set; }
}
public class Company
{
public int CompanyId { get; set; }
public string CompanyType { get; set; }
public string Name { get; set; }
public virtual ICollection<User> Users { get; set; }
public virtual ICollection<CompanyInfo> CompanyInfos { get; set; }
public virtual ICollection<CompanyFile> CompanyFiles { get; set; }
public virtual ICollection<SellerDebtor> SellerDebtorDebtorCompanies { get; set; }
public virtual ICollection<SellerDebtor> SellerDebtorSellerCompanies { get; set; }
}
目前,我遇到了以下错误:
System.Data.SqlClient.SqlException: Invalid column name 'DebtorCompany_CompanyId'.
Invalid column name 'SellerCompany_CompanyId'.
Invalid column name 'Company_CompanyId'.
Invalid column name 'Company_CompanyId1'.
理想情况下,我希望能够保持关系的命名。
我猜我需要设置一些属性,但我不确定该设置什么。