30

I'm trying to rewrite old library to use EntityFramework Core and I can't figure out how to begin transaction with specific isolation level.

Previously I was able to do something like this:

DbContext.Database.BeginTransaction(IsolationLevel.Snapshot);

What is alternative implementation in the EntityFramework Core?

Pavel
  • 1,015
  • 3
  • 13
  • 27

2 Answers2

42

The EF Core code is exactly the same.

DbContext.Database.BeginTransaction(IsolationLevel.Snapshot);

The only difference is that in EF Core the method with isolation level (as many others) is an extension method, defined in RelationalDatabaseFacadeExtensions class, and importantly, located in Microsoft.EntityFrameworkCore.Relational assembly.

So if you have using Microsoft.EntityFrameworkCore; and don't see it, add reference to the Microsoft.EntityFrameworkCore.Relational.dll assembly / package.

Ivan Stoev
  • 195,425
  • 15
  • 312
  • 343
3

In addition to Ivan Stoev's answer, it is also important to use System.Data.IsolationLevel and not System.Transactions.IsolationLevel when calling BeginTransaction method.

MatrixRonny
  • 437
  • 3
  • 11