1

我想做这样的事情:

context.Entry(oldEntity).CurrentValues.SetValues(newEntity);

我使用 EF 4.0,所以我知道我可以使用 EF 4.0context.ObjectStateManager来实现相同的目标

我看不到任何设置值的方法。我有ChangeObjectState, ChangeRelationshipState,ChangeRelationshipState可用的功能。

事实上我有这个错误:An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key.

所以我需要修改实体而不是附加它来解决我的问题。

4

1 回答 1

1

试试这个:

objectStateManager.GetObjectStateEntry(oldEntity).ApplyCurrentValues(newEntity);
于 2013-09-18T16:23:13.823 回答