Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TransactionScopeAsyncFlowOption and Isolation Level?

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.

like image 237
sagesky36 Avatar asked May 02 '14 14:05

sagesky36


People also ask

What is transactional isolation levels?

Transaction isolation levels are a measure of the extent to which transaction isolation succeeds. In particular, transaction isolation levels are defined by the presence or absence of the following phenomena: Dirty Reads A dirty read occurs when a transaction reads data that has not yet been committed.

What are isolation levels in SQL Server?

Isolation is the separation of resource or data modifications made by different transactions. Isolation levels are described for which concurrency side effects are allowed, such as dirty reads or phantom reads.

What is isolation level in C#?

Transactions specify an isolation level that defines the degree to which one transaction must be isolated from resource or data modifications made by other transactions. Isolation levels are described in terms of which concurrency side effects, such as dirty reads or phantom reads, are allowed.

What is isolation level in database?

What is an “Isolation Level”? Database isolation refers to the ability of a database to allow a transaction to execute as if there are no other concurrently running transactions (even though in reality there can be a large number of concurrently running transactions).


1 Answers

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)) 
{
}
like image 185
bkaid Avatar answered Nov 13 '22 05:11

bkaid