EF:An entity object cannot be referenced by multiple instances of IEntityChangeTracker

问题
在调用Attach(user)时报告以下错误:
An entity object cannot be referenced by multiple instances of IEntityChangeTracker

原因
实体对象user的DbContext还没关闭,此时不允许再Attach到另一个DbContext上。
Attach的实体对象,必须是脱离DbContext的管制。

解决
先关闭做查询的DbContext,再Attach到做更新的DbContext中。

原文地址:https://www.cnblogs.com/ego/p/2506070.html