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中。

posted @ 2012-05-17 13:30  深圳大漠  阅读(2549)  评论(0编辑  收藏  举报