Copy Entity Framework Object

前端 未结 5 1797
面向向阳花
面向向阳花 2021-01-31 21:52

I have a EF4.1 class X and I want to make copy of that plus all its child records. X.Y and X.Y.Z

Now if I do the following it returns error.

The property \'X.ID\

5条回答
  •  被撕碎了的回忆
    2021-01-31 22:35

    You need to make correct deep copy of the whole entity graph - the best way is to serialize the original entity graph to memory stream and deserialize it to a new instance. Your entity must be serializable. It is often used with DataContractSerializer but you can use binary serialization as well.

提交回复
热议问题