I am evaluating EF for my new applications.
How can I globally change the IsolationLevel of all EF transactions in an application? Example: Suppose I want to use the "Read Committed Snapshot".
While it is normal to indicate IsolationLevel when I explicitly need a TransactionScope anyway (see code below) it would be ugly to encapsulate every EF save operation in TransactionScope.
'OK Using tsc As New TransactionScope(TransactionScopeOption.RequiresNew, TransactionOption.ReadCommitted) UpdateShoppingCart EnqueueNewOrder SendConfirmationEmail tsc.Complete End Using 'Is this really the only way to avoid Serializable? Using tsc As New TransactionScope(TransactionScopeOption.RequiresNew, TransactionOption.ReadCommitted) _ctx.SaveChanges() tsc.Complete End Using Class TransactionOption Public Shared ReadOnly ReadCommitted As New TransactionOptions() With { .IsolationLevel = IsolationLevel.ReadCommitted, .Timeout = TransactionManager.DefaultTimeout } End Class
I guess mixing IsolationLevles is not a good idea. Am I really wrong?
With Serializable and SQL Server (unlike Oracle), inserting a simple innocent looking read can cause conversion lock locks.
From the EF FAQ: "It is recommended that you use READ COMMITTED transactions and use READ COMMITTED SNAPSHOT ISOLATION if you want readers to not block writers and writers not to block readers."
I donβt understand why EF uses Serializable by default and makes it difficult to change the default isolation level - with SQL Server (as opposed to tiered Oracle usage), by default for the pessimistic concurrency model. The configuration option should be very easy to implement - or am I missing something here?
Peter Meinl
source share