我会尝试解释我的问题,但老实说我什至无法理解。在对我的数据库中的几个表进行多次更改后,现在我尝试创建一个外键,但在更新 EDMX 时出现此错误。
gHOP.msl(410,10) : error 3007: Problem in Mapping Fragments starting at lines 410,
1511: Non-Primary-Key column(s) [UserGUID] are being mapped in both fragments to different conceptual side properties - data inconsistency is possible because the corresponding conceptual side properties can be independently modified.gHOP.msl(1511,6) : error 3012: Problem in Mapping Fragments starting at lines 410, 1511: Data loss is possible in Itinerary.UserGUID. An Entity with Key (PK) will not round-trip when: (PK does NOT play Role 'Itinerary' in AssociationSet 'FK_Itinerary_Users' AND PK is in 'Itinerary' EntitySet)
gHOP.msl(410,10) : error 3012: Problem in Mapping Fragments starting at lines 410, 1511: Data loss is possible in Itinerary.UserGUID. An Entity with Key (PK) will not round-trip when: (PK is in 'Itinerary' EntitySet AND PK does NOT play Role 'Itinerary' in AssociationSet 'FK_Itinerary_Users' AND Entity.UserGUID is not NULL)
老实说,这是一场噩梦,因为我不明白发生了什么。尽管我已经放弃并且我不会创建 FK,但如果有人至少可以给我一个提示,我将非常感激。
谢谢
最佳答案
不确定您对模型有多少访问/控制权,但我之前在更新数据库中的实体然后尝试更新模型时遇到过类似的问题。我通常只是从您在数据库中编辑的模型中删除实体!没有他们重建。然后在构建后重新添加它们。我发现当在数据库中进行结构/关系更改时,Visual Studio 并不总是能成功更新模型。
关于c# - Entity Framework 数据库优先与 SQL Server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10829829/