6

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.

sagesky36
  • 4,542
  • 19
  • 82
  • 130
  • "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 May 02 '14 at 14:12
  • I can only set the isolation level using TransactionScope, but NOT TransactionScopeAsyncFlowOption I meant to say... – sagesky36 May 02 '14 at 14:14
  • Why not? I'm not familiar with the flow option setting. – usr May 02 '14 at 14:15
  • There appears to be no isolation settings for it. You can read about if you search on TransactionScopeAsyncFlowOption. – sagesky36 May 02 '14 at 14:29
  • 4
    What about using this ctor? http://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 May 02 '14 at 14:44

1 Answers1

15

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)) 
{
}
bkaid
  • 51,465
  • 22
  • 112
  • 128