打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
EF修改数据遇到的问题及解决办法
报错信息:

Attaching an entity of type failed because another entity of the same type already has the same primary key value. This can happen when using the 'Attach' method or setting the state of an entity to 'Unchanged' or 'Modified' if any entities in the graph have conflicting key values. This may be because some entities are new and have not yet received database-generated key values. In this case use the 'Add' method or the 'Added' entity state to track the graph and then set the state of non-new entities to 'Unchanged' or 'Modified' as appropriate.

解决办法:

db.Entry<BussinessData>(实体).CurrentValues.SetValues(传过来的实体形参);

这样保证只修改需要修改的部分
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Entity Framework Add/Attach and Entity States
关于EF框架EntityState的几种状态
MVC实用架构设计(三)——EF-Code First(1):Repository,UnitOfWork,DbContext
C#中DataGridView绑定了DataTable后,通过代码修改DataGridView中的数据,总有一行(被修改过并被用户选中的行集合中索引为0的行)不能被UpDate回数据库的问题和解决办法
EF Core 基础知识
【asp.net core 系列】8 实战之 利用 EF Core 完成数据操作层的实现
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服