[转] EF cannot be tracked because another instance of this type with the same key is already being tracked
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);
[转] EF cannot be tracked because another instance of this type with the same key is already being tracked的更多相关文章
- The instance of entity type 'Menu' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked.
这里记录一个在使用.net core中ef core执行数据库操作时遇到的问题: 我在代码中使用DbContext下的Update方法准备将更改后的数据像这样步到数据库: _context.Menus ...
- The instance of entity type 'xxxx' cannot be tracked because another instance with the same key value for {'Id'} is already being tracked.
一.问题描述 问题:The instance of entity type 'xxxx' cannot be tracked because another instance with the sam ...
- type parameters of <T>T cannot be determined; no unique maximal instance exists for type variable T with upper bounds int,java.lang.Object
今天在进行代码检查的时候出现下面的异常: type parameters of <T>T cannot be determined; no unique maximal instance ...
- EF 更新实体 The instance of entity type 'BabyEvent' cannot be tracked because another instance
加上AsNoTracking. 人不能两次踏入同一条河. 我 就踏入了.o(╥﹏╥)o
- The instance of entity type 'manager' cannot be tracked because another instance with the same key value for {'id'} is already being tracked. When attaching existing entities, ensure that only one ent
最近在用ASP.NET CORE时遇到一些问题,现记录下: 出现上述错误,即在更新实体数据时出现的错误 services.AddDbContext<StoreContext>(c => ...
- EF关于报错Self referencing loop detected with type的原因以及解决办法
1)具体报错 { "Message": "出现错误.", "ExceptionMessage": "“ObjectContent` ...
- EF 6.0 The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. c#中的时间
在SQL server 中,有两种日期时间类型: 1.DateTime 它的范围是 1753-1-1 至 9999-12-31 2.DateTime2 它的满园是 0001-01-01 至 9999- ...
- 使用Ef查询出现的问题The cast to value type 'System.Boolean' failed because the materialized value is null.的解决方法
把值类型的系统.布尔的失败是因为物化值是null.结果类型的泛型参数或查询必须使用可空类型. 解决方法: 请确保你查询中的字段值不为空或者做为空判断
- EF 5 最佳实践白皮书
Performance Considerations for Entity Framework 5 By David Obando, Eric Dettinger and others Publish ...
随机推荐
- ASP.NET -- 获取浏览器信息
1. 获取浏览器信息 private void GetBrowserInfo() { StringBuilder sb = new StringBuilder(); sb.AppendLine(str ...
- [SinGuLaRiTy] 高级搜索算法
[SinGuLaRiTy-1039] Copyright (c) SinGuLaRiTy 2017. All Rights Reserved. 迭代加深搜索(ID) 迭代加深搜索,实质上就是限定下界的 ...
- php代码审计1(php.ini配置)
1.php.ini基本配置-语法 大小写敏感directive = value(指令=值)foo=bar 不等于 FOO=bar 运算符| & - ! 空值的表达方法foo = ;fo ...
- J2EE 的体系结构
J2EE 即Java2平台企业版,它提供了基于组件的方式来设计.开发.组装和部署企业应用.J2EE使用多层分布式的应用模型,这个多层通常通过三层或四层来实现: 1.客户层,运行在客户计算机上的组件. ...
- SDUT OJ 数据结构实验之串二:字符串匹配
数据结构实验之串二:字符串匹配 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...
- (转)VS2010实用快捷键
1,Visual Studio 2008自带的1000多个 Windows 系统使用的各种图标.光标和动画文件在Visual Studio 2008的安装目录下,/Microsoft Visual S ...
- wpa_supplicant
一 函数接口介绍 wpa_ctrl_open接口用来打开wpa_supplicant的控制接口,在UNIX系统里使用UNIX domain sockets,而在Windows里则是使用UDP sock ...
- Linux 使用echo向文件末尾追加命令
//echo后边用单引号包围要添加的内容 echo 'add content'>>/home/data/test.sh 注意>>表示在原来的文件末尾上进行追加,如果使用的是&g ...
- 三个常用的PHP图表类库
Jpgraph 只要把example中的require_once路径改了就放进来用吧,我下的是最新版的jpgraph-3.5.0b1,反正测试嘛,我记得跟3.0.7还是有差别的,把文件名都重新命名过了 ...
- 【floyd】【bitset】洛谷 P1841 [JSOI2007]重要的城市 题解
bitset玄学完美优化复杂度? 题目描述 参加jsoi冬令营的同学最近发现,由于南航校内修路截断了原来通向计算中心的路,导致去的路程比原先增加了近一公里.而食堂门前施工虽然也截断了原来通向计 ...