簡體   English   中英

實體框架6特定列映射

[英]Entity Framework 6 specific column mapping

在SQL中,我會告訴數據庫外鍵約束是什么。

但是流暢的EF6顯然沒有辦法讓我指定綁定集合時要使用的列。

是否不可能告訴DbModelBuilder確切的綁定關系的列? 還是一直要求成為主鍵?

Table_Person id int // pkey. Multiple people records UniqueID int // the unique person sometext varchar(256) // database therefore tracks changes to this, since unique person can have many records (pkeys). pkey id int // pkey. Multiple people records UniqueID int // the unique person sometext varchar(256) // database therefore tracks changes to this, since unique person can have many records (pkeys). id int // pkey. Multiple people records UniqueID int // the unique person sometext varchar(256) // database therefore tracks changes to this, since unique person can have many records (pkeys).

Table_Address id int //pkey fk_unique int // should map to UniqueID of person, NOT the pkey. line1 varchar(512) state varchar(64) etc id int //pkey fk_unique int // should map to UniqueID of person, NOT the pkey. line1 varchar(512) state varchar(64) etc一個唯一的人有很多記錄,並且他們的uniqueID(不是pkey)有很多關聯的地址。 實際的結構要比這復雜得多。 但是我正在尋找一種從根本上做到這一點的方法...

非常希望在Persons模型中具有ICollection<Address> Addresses 但是要實現代碼優先的遷移,這似乎是不可能的嗎? 是的,我可以Add-Migration ,然后手動修改生成的代碼/ sql。 但這不是要害嗎? 還是這是慣例?

如果您能夠修改數據庫模式,則可以將人員的唯一ID放入他們自己的名為“ Person”的表中,並將現有表重命名為“ PersonVersion”。 然后將FK轉到“ PersonVersion”和“地址”上的新“ Person”表。 最后,在您的應用程序代碼中創建Person,PersonVersion和Address模型,EF應該毫無問題地綁定。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM