某处,我有
Order o = db.Orders.First(o => o.ID == 6);
...
o.Details.Add(new OrderDetail(1,2));
并按下按钮点击事件
...
Order o1 = db.Orders.FirstOrDefault(o2=>o2.ID == o.ID);
o1.Details.Clear();
foreach(OrderDetail od in o.Details){
o.Details.Add(od);
}
db.SaveChange();
...
我遇到了这个错误:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.Entity.dll
Additional information: The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects
似乎我无法修改由另一个DbContext或手工创建的对象,是否有工作方式?