在 EF Core 中使用 IsolationLevel 开始事务 [英] BeginTransaction with IsolationLevel in EF Core

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

问题描述

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

以前我能够做这样的事情:

DbContext.Database.BeginTransaction(IsolationLevel.Snapshot);

EntityFramework 核心中的替代实现是什么?

解决方案

EF Core 代码完全一样.

DbContext.Database.BeginTransaction(IsolationLevel.Snapshot);

唯一的区别是在 EF Core 中 具有隔离级别的方法(与许多其他方法一样)是一种扩展方法,定义在RelationalDatabaseFacadeExtensions 类,重要的是,位于 Microsoft.EntityFrameworkCore.Relational 程序集.

因此,如果您有 using Microsoft.EntityFrameworkCore; 并且没有看到它,请添加对 Microsoft.EntityFrameworkCore.Relational.dll 程序集/包的引用.>

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?

解决方案

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.

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

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