[英]Entity Framework: Inheritance with same name for parent and child primary key
我正在嘗試在兩個表之間進行實體框架繼承。
父母:
ParentTable
Id: int primary key
CustomAttribute: int
孩子:
ChilTable
Id: int primary key (not the same one as the parent, Child specific Id)
TCId: int foreign key to parent
SomeInformation: String
由於某些原因,我想繼續命名“ Id”作為ParentTable和ChildTable的主鍵。 這不會打擾EntityFramwork,因為我為子表創建了另一個名稱為“ CId”的自定義屬性:
Child1表映射如下:
但是當我“驗證”模型時,VS2010會說:
Error 3002: Problem in mapping fragments starting at line 103:Potential runtime violation of table Child1's keys (Child1.Id): Columns (Child1.Id) are mapped to EntitySet Parents's properties (Parents.CId) on the conceptual side but they do not form the EntitySet's key properties (Parents.Id).
基本上,我理解Entity Framework遇到了一個問題,因為我們將表的主鍵映射到了不是Entity鍵的屬性,但是我們應該如何使用繼承呢?
僅在“子代”表中沒有主鍵時才允許繼承嗎? 我應該將主鍵作為“簡單鍵”嗎?
提前致謝...
EF希望孩子的Id
PK也能成為父母的FK。 因此, Child.Id
既是PK又是FK。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.