问题描述
我一直在尝试从其引用更新实体,如下所述
我收到此错误
System.Data中出现类型'System.InvalidOperationException'的异常。 Entity.dll但未在用户代码中处理
附加信息:IEntityChangeTracker的多个实例无法引用实体对象。
如果我不想要如何实现这一点单独处理每个实体
用户[id名称]
操作[id text userid resultId]]
结果[id resulttxt]
i been trying to update entity from its reference as explained below
iam getting this error
An exception of type 'System.InvalidOperationException' occurred in System.Data.Entity.dll but was not handled in user code
Additional information: An entity object cannot be referenced by multiple instances of IEntityChangeTracker.
how to make this happen if i dont want to deal with each entity alone
user[id name]
action[id text userid resultId]]
result[id resulttxt]
public static void test1(action act) {
act.text="132";
act.user.name="test";
act.result.resulttxt="test";
testEntities e = new testEntities();
e.actions.Attach(act);
e.SaveChanges();
}
testEntities b = new testEntities();
action act = b.actions.Include("user").Include("result").Where(x => x.id == 9).FirstOrDefault();
test1(act);
推荐答案
public static void test1(action act) {
act.text="132";
act.user.name="test";
act.result.resulttxt="test";
}
testEntities b = new testEntities();
action act = b.actions.Include("user").Include("result").Where(x => x.id == 9).FirstOrDefault();
test1(act);
b.SaveChanges();
以及它是否有效,但为什么我无法附加该实体并保存其他更改context
well yes it worked but why i cant attach that entity and save change in the other context
这篇关于通过关系更新实体时出现IEntityChangeTracker错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!