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.
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.
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.
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 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).
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))
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With