问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/55208184/begintransaction-with-isolationlevel-in-ef-core