1

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.

1 Answer 1

3

What do you need exactly is this:

First Attach the detached object X to the DataContext the change it's state to EntityState.Modified, the run SaveChanges and it will update the database based on your changes.

Just remember to set the ID of Y to ID of X which is the primary key AFAIU.

For more information look at http://msdn.microsoft.com/en-US/data/jj592676

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.