6
votes

I'm using Entity Framework 6.1 in a WCF service and wanted to surround my SELECT query with a READ UNCOMMITTED Isolation level since other batch updates will be inserted into the table I'm reading and don't want to lock those batch updates from occurring when a READ is performed on the table. This basically simulates a SELECT WITH NOLOCK.

This code was also being used in an asynchronous fashion. Hence, I could not simply use TransacactionScope. Note that I'm also using the .Net 4.5.1 framework.

I could set the Isolation Level on TransactionScope to ReadUncommitted, but TransactionScopeOption has the default of ReadCommitted. I don't see any way to change the Isolation Level.

Is there any way to change the Isolation Level? If I can't set the Isolation Level, would my query be okay to run under the above circumstances.

Actually, if I can't set the Isolation level to "NOLOCK", there is no need for me to even include the TransactionScopeAsyncFlowOption.

1
"I could set the Isolation Level on TransactionScope to ReadUncommitted, but TransactionScopeOption has the default of ReadCommitted. I don't see any way to change the Isolation Level." That is a contradiction. You say you can set the level but somehow you can't. Why? - usr
I can only set the isolation level using TransactionScope, but NOT TransactionScopeAsyncFlowOption I meant to say... - sagesky36
Why not? I'm not familiar with the flow option setting. - usr
There appears to be no isolation settings for it. You can read about if you search on TransactionScopeAsyncFlowOption. - sagesky36
What about using this ctor? msdn.microsoft.com/en-us/library/dn249390(v=vs.110).aspx I'm trying to understand the problem here because the solution seems too simple. - usr

1 Answers

14
votes

Use the constructor option with the TransactionScopeAsyncFlowOption specified as the third parameter, not the the first:

using (var scope = new TransactionScope(
    TransactionScopeOption.Required,  
    new TransactionOptions { IsolationLevel = IsolationLevel.ReadUncommitted },
    TransactionScopeAsyncFlowOption.Enabled)) 
{
}