[英]Implementing Fluent API kind of method in C# for ef Code-First
我首先使用 EF 4.1 代碼,並使用流利的 API 進行實體配置。
我正在使用以下方式來配置我的實體。 幾乎我的數據庫中的每個表鍵都是“ICustomerId + TableKey”的組合,因此,每個外鍵關系都需要它來引用它。
HasRequired(x => x.Company)
.WithMany(y => y.CompanyContacts)
.HasForeignKey(p => new { p.ICustomerID, p.CompanyID })
.WillCascadeOnDelete(false);
我想在我的基礎 class(繼承自 EntityTypeConfiguration)中實現一個方法,該方法將采用 TargetEntity、TargetKey,並將執行上述外鍵創建(通過自動包含 ICustomerId。我的 Clas 定義:-
public class CompanyContactsMapping
: BaseInsightTypeConfiguration<CompanyContacts,int>
{...
public class BaseInsightTypeConfiguration<T, TKeyType>
: EntityTypeConfiguration<T> where T : BaseInsightEntity<TKeyType>
{...
任何想法,我該如何實現這種方法?
KeyType .... 你確定,那種類型的鑰匙會唯一地識別你的鑰匙嗎? 我可能會用名稱和反射 go 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.