I am using EF 4.1 code first, and using fluent API for entity Configuration.
I am using following way to configure my entities. Almost every table key in my db is composite of "ICustomerId + TableKey", hence, every foreign key relationship requires it to refer it also.
HasRequired(x => x.Company)
.WithMany(开发者_如何学JAVAy => y.CompanyContacts)
.HasForeignKey(p => new { p.ICustomerID, p.CompanyID })
.WillCascadeOnDelete(false);
I want to implement a method in my base class (which inherits from EntityTypeConfiguration), which will take TargetEntity, TargetKey, and will perform above foreign key creation (by including ICustomerId automatically. My Clas Defintions:-
public class CompanyContactsMapping
: BaseInsightTypeConfiguration<CompanyContacts,int>
{...
public class BaseInsightTypeConfiguration<T, TKeyType>
: EntityTypeConfiguration<T> where T : BaseInsightEntity<TKeyType>
{...
Any Idea, how can I implement such method?
KeyType.... are you sure, that type of key will uniquely identify you key? I would go with names and reflection perhaps.
精彩评论