I have two same objects of type ‘Monitor’ that represents the data that will be written to the database. The first object X has the data that I want to update in the database. Object Y is the one that was read from the database using entity framework.
I want to copy all the data of object X, except the ID, to Object Y. The reason I want to do so is that I’ve already got object X populated but I don’t want to start copying each property value one by one. So in short, I want to merge the data (Except the ID) from object X to object Y, which Object Y is the object which is attached to the context. then when I run Savechanged(), object Y will be updated with the new data.
What do you need exactly is this:
First
Attachthe detached object X to theDataContextthe change it’s state toEntityState.Modified, the runSaveChangesand it will update the database based on your changes.Just remember to set the
IDofYtoIDofXwhich is the primary key AFAIU.For more information look at http://msdn.microsoft.com/en-US/data/jj592676