entity framework core 更新问题

DMPX 2016-06-26 06:38:48
InvalidOperationException: The instance of entity type 'User' cannot be tracked because another instance of this type with the same key is already being tracked. When adding new entities, for most key types a unique temporary key value will be created if no key is set (i.e. if the key property is assigned the default value for its type). If you are explicitly setting key values for new entities, ensure they do not collide with existing entities or temporary values generated for other new entities. When attaching existing entities, ensure that only one entity instance with a given key value is attached to the context.

获取User对象
_unitOfWork.Set<TEntity>().SingleOrDefault(filter);

更新User对象
base.Entry<TEntity>(item).State = EntityState.Modified;

ef4.0时有base.Entry<TEntity>(original).CurrentValues.SetValues(current);
ef core 找不到CurrentValues了
...全文
1188 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
quan01994 2016-07-29
  • 打赏
  • 举报
回复
不支持啊,刚刚出来的,哪会这么快支持。我最近也在看,还有你用用看使用ip作为Server看看,我这不行啊。死活连不上。

17,740

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧