TransactionScopeAsyncFlowOption and Isolation Level?

2.6k Views Asked by At

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

There are 1 best solutions below

0
bkaid On

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)) 
{
}