【发布时间】:2011-07-22 14:24:41
【问题描述】:
我首先使用 EF 4.1 代码,并使用 fluent API 进行实体配置。
我正在使用以下方式来配置我的实体。几乎我的数据库中的每个表键都是“ICustomerId + TableKey”的组合,因此,每个外键关系都需要它来引用它。
HasRequired(x => x.Company)
.WithMany(y => y.CompanyContacts)
.HasForeignKey(p => new { p.ICustomerID, p.CompanyID })
.WillCascadeOnDelete(false);
我想在我的基类(继承自 EntityTypeConfiguration)中实现一个方法,该方法将采用 TargetEntity、TargetKey,并将执行上述外键创建(通过自动包含 ICustomerId. 我的班级定义:-
public class CompanyContactsMapping
: BaseInsightTypeConfiguration<CompanyContacts,int>
{...
public class BaseInsightTypeConfiguration<T, TKeyType>
: EntityTypeConfiguration<T> where T : BaseInsightEntity<TKeyType>
{...
任何想法,我该如何实现这种方法?
【问题讨论】:
标签: c# linq linq-to-entities entity-framework-4.1 expression-trees