Copy Entity Framework Object

前端 未结 5 1796
面向向阳花
面向向阳花 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:20

    C is not a copy it is the record, the error you are getting is because you are trying to update it's primary key, even if you weren't it still wouldn't work. You need to make a new X entity and then copy the values from the properties of the retrieved entity and then insert the new entity.

提交回复
热议问题