EF Core中具有IsolationLevel的BeginTransaction [英] BeginTransaction with IsolationLevel in EF Core

查看:294
本文介绍了EF Core中具有IsolationLevel的BeginTransaction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图重写旧库以使用EntityFramework Core,但我不知道如何以特定的隔离级别开始事务。

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);

EntityFramework Core中的替代实现是什么?

What is alternative implementation in the EntityFramework Core?

推荐答案

EF核心代码完全相同。

The EF Core code is exactly the same.

DbContext.Database.BeginTransaction(IsolationLevel.Snapshot);

唯一的区别是,在EF Core中,具有隔离级别的方法(以及许多其他方法)是扩展名方法,该方法在 RelationalDatabaseFacadeExtensions中定义类,并且重要的是位于 Microsoft.EntityFrameworkCore.Relational

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.

因此,如果您有使用Microsoft.EntityFrameworkCore; 而看不到,请添加对 Microsoft.EntityFrameworkCore.Relational.dll 程序集/程序包。

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

这篇关于EF Core中具有IsolationLevel的BeginTransaction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆