When I use oeSaveChanges() in Entity Framework, what is the default transaction isolation level?

.net ado.net entity-framework transactions

Question

When I use oeSaveChanges() in Entity Framework, what is the default transaction isolation level? It is nowhere to be found. Does it need to be "Serializable"?

1
35
4/14/2011 8:14:51 AM

Accepted Answer

SaveChanges uses the execution ofDbTransaction for the retailer of the moment. This indicates that the database server's default transaction isolation level is set to the default setting. It is in SQL ServerREAD COMMITTED You may use to modify the amount of isolationTransactionScope You may also make an exception.SaveChanges wrap in your derived contextbase.SaveChanges() to the overriden method's scope directly.

public override void SaveChanges()
{
    // Default isolation level for TransactionScope is Serializable
    using (var scope = new TransactionScope())
    {
        base.SaveChanges();
        scope.Complete();
    }
}

This code may be further enhanced to enable passing isolation level toSaveChanges etc. Once you begin adjusting the amount of isolation, you should continue to do so. This indicates that since connections and The isolation level is set for each connection. are reused when utilizing connection pooling, you need set isolation level each time you wish to conduct a transaction.

Edit: In EF6, the default transaction level has changed toREAD COMMITTED SNAPSHOT

44
10/30/2013 10:16:53 AM

Popular Answer

The System.Transactions architecture always generates Serializable transactions by default.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow