2012-01-07 82 views
0

我有2个对象,一个链接到datacontext,其次不是。我需要从第二个到第一个复制完整的数据。怎么做?如果我尝试只是如何在以下情况下复制数据

obj1 = obj2; 

我得到EntityDataContext误差不附

回答

2

的EF框架,现在有很多级别和版本。当您使用ObjectContext时,您可以使用ApplyCurrentValues

T ApplyCurrentValues<T>(string entitySetName, T currentEntity) 
+0

+1这是正确答案,但它只适用于标量和复杂属性。它不会处理导航属性和EF有[没有自动解决方案](http://stackoverflow.com/questions/3635071/update-relationships-when-saving-changes-of-ef4-poco-objects/3635326#3635326 )。 – 2012-01-07 22:49:35