Alternative to TransactionScope of System.Transaction assembly in .net core framework

后端 未结 2 916
难免孤独
难免孤独 2021-01-03 23:07

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)

2条回答
  •  忘掉有多难
    2021-01-04 00:01

    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

    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.

    Original answer

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

提交回复
热议问题