Transactions and Concurrency

All selections and updates are atomic and made inside of a SQL Server transaction. When you load an object, a collection of objects, or multiple collections, these items will exist inside of an Entity Framework context. This is a container that holds all related information. You can have any number of contexts loaded. They will not interfere with each other and have no knowledge of each other. Every object exists inside of a context with strongly-typed objects.

A context comes into play when objects are persisted. When the SaveChanges method of a context is called, its entire contents are persisted in one SQL transaction. All add, update, and delete actions are run in the necessary order against the database. The order is very important since referential integrity dictates many situation where there should not be orphans when inserting (like Customer/Orders). When deleting it is important to remove children before parents. All of these calculation are performed by the framework. There is no need to write it yourself.

Another need to is perform CRUD operations on multiple tables in one transaction. This is implied for all objects in the same context. To use this functionality we need to ensure that all objects are in the same context.

Last edited May 7, 2012 at 10:32 PM by codetools, version 5


No comments yet.