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

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

问题描述

System.Transaction程序集目前不属于.net核心框架(请参阅 https ://github.com/dotnet/corefx/issues/2949 ).在我的应用程序(asp.net核心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 Core 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天全站免登陆