Joined January 2015
·

Michael Denny

Parma (Italy)
·
·

EF does not change the isolation level, the problem with serializable comes from a sad decision on the default isolation level of TransactionScope. EF opens transactions in read commited mode, but if you wrap it in a TransactionScope, the transaction will be serializable by default and EF will use that.

Solution: simply create the TransactionScope specifying the isolation level = read commited

using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }))
{
    scope.Complete();
}

Sources:

https://msdn.microsoft.com/en-us/data/dn456843.aspx

"In either case, the isolation level of the transaction is whatever isolation level the database provider considers its default setting. By default, for instance, on SQL Server this is READ COMMITTED."

http://referencesource.microsoft.com/#System.Transactions/System/Transactions/TransactionManager.cs,4853e046f5438f90,references

internal static System.Transactions.IsolationLevel DefaultIsolationLevel
{
    get
    {
        if ( DiagnosticTrace.Verbose )
        {
            MethodEnteredTraceRecord.Trace( SR.GetString( SR.TraceSourceBase ),
                "TransactionManager.get_DefaultIsolationLevel"
                );
            MethodExitedTraceRecord.Trace( SR.GetString( SR.TraceSourceBase ),
                "TransactionManager.get_DefaultIsolationLevel"
                );
        }

        return IsolationLevel.Serializable;
    }
}
Achievements
1 Karma
0 Total ProTip Views