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.
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.
Transaction Control: There are the following commands used to control transactions. COMMIT To save changes. ROLLBACK To rollback the changes. SET TRANSACTION Places a name on a transaction.
If you want to rollback a transaction, you should not call the Complete method within the transaction scope. For example, you can throw an exception within the scope. The transaction in which it participates in will be rolled back.
Ambient Transaction If you see the use of TransactionScope, you will not find transaction related anything sent to any method or setting any property. A code block is automatically attached with the transaction if that code is in any TransactionScope.
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();
}
}
Just wanted to leave a comment here in case anybody wandered by this post while researching this issue. I ran into this randomly on .net core 2.1 using Dapper, which includes System.Data.SqlClient 4.5.0 by default. Adding version System.Data.SqlClient 4.5.1 independently via nuget worked. So it seems this has been fixed as of 4.5.1.
The following are the relevant sections of my csproj file:
<ItemGroup>
<PackageReference Include="Dapper" Version="1.50.5" />
<PackageReference Include="System.Data.SqlClient" Version="4.5.1" />
</ItemGroup>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With