gpt4 book ai didi

asp.net - EntityFramework.dll 中发生了 'System.Data.Entity.Infrastructure.DbUpdateException' 类型的异常,但未在用户代码中处理

转载 作者:行者123 更新时间:2023-12-04 18:42:00 26 4
gpt4 key购买 nike

我映射了两个表并在 MVC 中创建了脚手架。单击创建按钮时,在表单中填写数据后,出现以下错误。

An exception of type 'System.Data.Entity.Infrastructure.DbUpdateException' occurred in EntityFramework.dll but was not handled in user code

Additional information: A value shared across entities or associations is generated in more than one location. Check that mapping does not split an EntityKey to multiple store-generated columns.

最佳答案

当您有一个子类型表映射,但其主键设置为自动生成时,通常会发生此问题。这是有问题的,因为 EF 将根据根实体的键显式设置值。

如果以上确实是问题,那么要解决它,请将子表的“ Identity Specification ”设置为false。即删除 StoreGeneratedPattern="identity" 来自 EDMX。

关于asp.net - EntityFramework.dll 中发生了 'System.Data.Entity.Infrastructure.DbUpdateException' 类型的异常,但未在用户代码中处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24103916/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com