[转] EF cannot be tracked because another instance of this type with the same key is already being tracked
2024-09-25 04:51:34
cannot be tracked because another instance of this type with the same key is already being tracked
If you load the entity from the context you cannot attach an entity with the same key again.
The first entity is still kept in internal context cache and context can hold only one instance with given key value per type (it is called identity map and I described it here in other situation).
You can solve it by detaching former instance but you don't have to. If you only need to save new values you can use this:
- ObjectContext API:
context.YourEntitySet.ApplyCurrentValues(newEntity);
- DbContext API:
context.Entry(oldEntity).CurrentValues.SetValues(newEntity);
最新文章
- Can't connect to local MySQL server through socket '/tmp/mysql.sock'
- 当SVN服务器端IP地址发生变化时,客户端重新定位
- Django基础——Model篇(一)
- VIM中的折叠命令
- 定义函数def
- java--多线程之Runnable
- 教你怎么把iconfont转换成png透明图片
- 使用ffmpeg转码时遇到aac报错
- percona-toolkit 之 【pt-online-schema-change】说明【转】
- java数组的声明、创建和遍历
- unity仿微信飞机大战项目
- django 生产环境部署建议
- NUnit单元测试示例
- MVC 3.0学习笔记(自定义控件)
- mysql中Table is read only错误解决方法
- Spring Bean装配学习
- 微信怎样做SEO
- python int函数转换浮点型字符串的坑???
- 爬取lol皮肤
- scrapy从安装到爬取煎蛋网图片