You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Asp.net更新对象时遇System.InvalidOperationException错误求助

实体主键修改引发EF异常求助

异常信息

Value of member X of an object of type Y changed. A member defining the identity of the object cannot be changed. Consider adding a new object with new identity and deleting the existing one instead.

相关代码说明

  • 控制器编辑方法:实现POST请求的Edit逻辑,接收实体实例后尝试通过EF更新数据
  • 实体模型:包含作为对象标识的主键字段,以及其他业务属性

已尝试方案

  • 测试标识字段的赋值逻辑
  • 检查字符串类型主键的长度限制

以上方案均未解决问题,恳请各位提供解决方案,感谢!

内容的提问来源于stack exchange,提问作者Kenny Nguyễn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 14:05:17