.net 核心框架中 System.Transaction 程序集的 TransactionScope 的替代方案 [英] Alternative to TransactionScope of System.Transaction assembly in .net core framework

查看:21
本文介绍了.net 核心框架中 System.Transaction 程序集的 TransactionScope 的替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

System.Transaction 程序集目前不是 .net 核心框架的一部分(参见 https://github.com/dotnet/corefx/issues/2949).在我的应用程序(asp.net core mvc)中,我需要使用 TransactionScope 进行事务处理.

The System.Transaction assembly is not part of the .net core framework at the moment (see https://github.com/dotnet/corefx/issues/2949). In my application (asp.net core mvc) I need to use TransactionScope for transaction handling.

是否有适用于 .net 核心框架的替代事务处理?我曾尝试使用 Castle.Transactions 作为替代方案,目前也不支持.

Is there an alternative transaction handling which works with the .net core framework? I have tried to use Castle.Transactions as an alternative, which is also not supported at the moment.

推荐答案

更新 2.NET Core 2.0 现已发布.您可以使用此 API.请参阅 https://docs.microsoft.com/en-us/dotnet/api/system.transactions.transactionscope?view=netcore-2.0

Update 2 .NET Core 2.0 is out now. You can use this API. See https://docs.microsoft.com/en-us/dotnet/api/system.transactions.transactionscope?view=netcore-2.0

更新System.Transactions 将在NET 核心 2.0.请参阅 https://github.com/dotnet/core/blob/master/roadmap.md 了解即将发布的版本的详细信息.

Update System.Transactions will be available in NET Core 2.0. See https://github.com/dotnet/core/blob/master/roadmap.md for details on upcoming releases.

原答案

System.Transactions(或环境事务)未在 .NET Core 1.0.0 中实现,但可能会在未来版本中实现.

System.Transactions (or ambient transactions) is not implemented in .NET Core 1.0.0 but may be implemented in future versions.

您可以通过使用显式事务来解决此问题.

You can work around this by using explicit transactions.

        using (var connection = new SqlConnection(connectionString))
        {
            connection.Open();

            using (var transaction = connection.BeginTransaction())
            {
               // transaction.Commit();
               // transaction.Rollback();
            }
        }

这篇关于.net 核心框架中 System.Transaction 程序集的 TransactionScope 的替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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