2

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 Answer 1

3

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.

1
  • 1
    Just to add on your point - If you are changing the isolation level during the transaction then you may be violating some SOLID principles.
    – Zakk Diaz
    Mar 22, 2019 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.