Sharing of transaction fails on execution strategy retry #25946
Labels
area-save-changes
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-bug
Milestone
Within an "ExecuteInTransaction" operation I want to share a transaction between two contexts using
Database.UseTransaction(...)
. This works the first time, but if the execution block fails and is retried, the call toUseTransaction
throws the below exception.Exception
There appear to be two simple workarounds, though I'm not certain about their reliability:
Database.UseTransaction(null)
just before calling again with the actual transaction to shareDatabase.CurrentTransaction?.Dispose()
just beforeUseTransaction(...)
However, it would be better - if possible - not to require these workarounds. especially because of the slight difficulty in discovering the need for them due to it only happening on a retry. Perhaps the underlying transaction should be recognised as disposed / no longer in use?
Here is a repo, tried to keep it minimal while conveying a sense of the use-case for this scenario.
Code
Include provider and version information
EF Core version: 5.0.9, 6.0 daily
Database provider: Microsoft.EntityFrameworkCore.SqlServer
The text was updated successfully, but these errors were encountered: