c# - Entity Framework 数据库优先与 SQL Server

标签 c# sql-server entity-framework

我会尝试解释我的问题,但老实说我什至无法理解。在对我的数据库中的几个表进行多次更改后,现在我尝试创建一个外键,但在更新 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/

相关文章:

mysql - SQL Server 和 MySQL 表之间的双向同步

c# - 编辑 EF 实体列表的有效方法

ASP.net:由于数据库错误,无法使用网站管理工具

entity-framework - Azure应用程序见解不显示SQL命令文本

c# - 比较数据库中的日期时间时,“LIKE%”在更新查询中不起作用

c# - 从 Active Directory c# 检索图片

c# - 即使关注另一个控件,如何更改 ListView 选定行的背景色?

c# - winform c# 中的数据绑定(bind)错误

mysql - 如何在不使用 .net 工具的情况下将 mysql 数据库导入 Azure sql

sql-server - 检测SQL Server安装目录