替代.net核心框架中System.Transaction程序集的TransactionScope

MUG*_*G4N 18 transactions asp.net-core-mvc asp.net-core

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

题:

是否存在可与.net核心框架一起使用的备用事务处理?我曾尝试使用Castle.Transactions作为替代方案,目前也不支持.

nat*_*ter 18

更新2 .NET Core 2.0现已推出.您可以使用此API.请参阅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.

原始答案

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

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

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

            using (var transaction = connection.BeginTransaction())
            {
               // transaction.Commit();
               // transaction.Rollback();
            }
        }
Run Code Online (Sandbox Code Playgroud)

  • 它尚未发布.https://github.com/dotnet/corefx/pull/10089但是,添加了许多其他API以使.NET Core与.NET Framework更兼容. (2认同)