EF Core change isolation level programmatically?

.net c# entity-framework entity-framework-core

Question

I'm learning EF Core and trying to change the isolation level of a transaction instance.

Here is the code I set up a transaction instance with ReadUncommitted level :

var transaction = new CommittableTransaction(new TransactionOptions
{ IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted });

I tried the below code to make it ReadCommitted, but doesn't work as IsolationLevel property is read-only.

context.Database.GetEnlistedTransaction().IsolationLevel = IsolationLevel.ReadCommitted;

How can I do it programmatically?

1
0
3/22/2019 7:23:06 PM

Accepted Answer

There's no API for that, either because not all platforms support changing the transaction isolation level in-flight, or because it's a very unusual thing to attempt.

For SQL Server you can do this (if you really want to) with TSQL, but normally you just select the transaction isolation level a the beginning of the transaction.

2
3/22/2019 7:27:40 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow