It should be mentioned that explicitly starting a database transaction via call DbContext.Database.BeginTransaction() will lead to exception if it is done inside ambient transaction scope.
The thrown exception is:
System.InvalidOperationException: 'An ambient transaction has been detected. The ambient transaction needs to be completed before beginning a transaction on this connection.'
Code:
using (var ambientTxn = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
using (var txn = await context.Database.BeginTransactionAsync())
{
}
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
It should be mentioned that explicitly starting a database transaction via call
DbContext.Database.BeginTransaction()will lead to exception if it is done inside ambient transaction scope.The thrown exception is:
Code:
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.