![](/img/trans.png)
[英]How do I map an inherited table with a composite key using Entity Framework code-first?
[英]EF Code-First How To Read A From Table With A Composite Key
我已經使用EntityFramework 6 Code First創建了一個SQL Server表,該表具有一個復合鍵:檢查員ID和轄區ID。 這些字段的每個組合在表上應唯一,因此在組合鍵上也應唯一。
類/表定義:
public class InspectorJurisdiction
{
[Key]
[Column(Order = 1)]
public int inspectorId { get; set; }
[Key]
[Column(Order = 2)]
public int jurisId { get; set; }
}
網絡環境:
public DbSet<InspectorJurisdiction> InspectorJurisdictions { get; set; }
我正在使用存儲庫設計模式來與創建的表進行交互,該表具有存儲庫類/接口和Web上下文。
我該如何接線
var record = context.InspectorJurisdictions.Find(????)
語句使用組成復合鍵的兩個字段從數據庫表中讀取?
您不應該為多對多映射創建實體。 相反,每個實體Inspector
和Jurisdiction
應包含其他對象的集合。
有關如何正確設置的更多信息,請查看文檔https://www.entityframeworktutorial.net/code-first/configure-many-to-many-relationship-in-code-first.aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.