Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
MSDN Library

How to: Apply Changes Made to a Detached Object

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

This topic provides an example of how to apply to an object updates made to a detached instance of the same object. This procedure is used when an object is updated remotely and set back to the server to persist the changes. If the object were simply attached to an object context at the server, updates would be lost or the operation would fail if the object was already in the object context. This occurs because objects are attached in an Unchanged state. For more information, see Attaching and Detaching Objects.

The example in this topic is based on the Adventure Works Sales Model. To run the code in this example, you must have already added the AdventureWorks Sales Model to your project and configured your project to use the Entity Framework. To do this, complete the procedures in How to: Manually Configure an Entity Framework Project and How to: Manually Define the Model and Mapping Files.

Example

In the following example, an updated SalesOrderDetail object is passed to the UpdateItemChanges method, along with the original object. This enables changes to be applied without querying for the object or having to persist it in memory. You can also retrieve the original object from the database instead of requiring the client to pass it.

See Also

Show:
© 2015 Microsoft