本文转自:http://stackoverflow.com/questions/6033638/an-object-with-the-same-key-already-exists-in-the-objectstatemanager-the-object

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);

最新文章

  1. Can't connect to local MySQL server through socket '/tmp/mysql.sock'
  2. 当SVN服务器端IP地址发生变化时,客户端重新定位
  3. Django基础——Model篇(一)
  4. VIM中的折叠命令
  5. 定义函数def
  6. java--多线程之Runnable
  7. 教你怎么把iconfont转换成png透明图片
  8. 使用ffmpeg转码时遇到aac报错
  9. percona-toolkit 之 【pt-online-schema-change】说明【转】
  10. java数组的声明、创建和遍历
  11. unity仿微信飞机大战项目
  12. django 生产环境部署建议
  13. NUnit单元测试示例
  14. MVC 3.0学习笔记(自定义控件)
  15. mysql中Table is read only错误解决方法
  16. Spring Bean装配学习
  17. 微信怎样做SEO
  18. python int函数转换浮点型字符串的坑???
  19. 爬取lol皮肤
  20. scrapy从安装到爬取煎蛋网图片

热门文章

  1. Xcode打包提交至itunes connect后,提交审核成功,随后出现二进制文件无效
  2. NSTimeZone时区
  3. 基于redis的分布式锁的分析与实践
  4. sql中日期转换
  5. kali linux之sqlmap
  6. Java面向对象之USB接口实例
  7. P3185 [HNOI2007]分裂游戏
  8. Query on a tree 树链剖分 [模板]
  9. 5、Numpy处理数据
  10. Java实现二维码生成的方法