entity-framework-coretransactionsdistributed-transactions

ASP.NET Core 6 and EF Core - distributed transaction


We have upgraded recently from .NET Core 2.2 to .NET 6.0 and we encounter several issues. One of them is related to using System.Transaction which somehow is being upgraded to distributed transaction for database operations that involve non-clustered database servers.

I searched but I was unable to find when/how a transaction scope is upgraded to distributed transaction?

We are using short lived contexts, so each write operation (we have 6 of them) in the transaction block creates a context and dispose of it when done.


Solution

  • This code is a hangfire job. We were using job cancellation token inside the transaction, which under the hood will trigger a database call.

    We should be using a regular cancellation token to cancel the job instead.