How to: Manage Transactions in the Entity Framework

[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 define a transaction that coordinates making changes to objects in an object context with other external operations. For more information, see Managing Connections and Transactions.

The example in this topic is based on the AdventureWorks 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 procedure in How to: Use the Entity Data Model Wizard. You must also have Microsoft Windows Message Queuing installed.


This example defines a TransactionScope. The TransactionScope ensures that changes to objects in the object context are coordinated with a message queue. The Entity Framework uses this transaction when it saves changes to the database. When an UpdateException occurs, the operation is retried up to two times. When the operation succeeds, the changes in the object context are accepted. For more information, see Managing Connections and Transactions.

This example uses a long-running object context, which is disposed after the transaction succeeds or after all retries have been attempted.

See Also