The following code opens a new transaction scope independent of any containing scope:
using (TransactionScope scope = new(TransactionScopeOption.Suppress, asyncFlowOption: TransactionScopeAsyncFlowOption.Enabled))
{
var connection = _connectionFactory.GetConnection()
await connection.QueryAsync(...); // e.g. call DB with Dapper
await connection.QueryAsync(...); // e.g. another call
}
(using Dapper)
How do I make a scope that is independent of any containing scope and does not start a new transaction? Essentially, I want the "suppress" option as above, but in a "non-transaction scope".
You can run a thread without passing it a
DependentTransaction. It will be independent. Create a function that runs the queries and use this: