I want to group multiple method calls involving DapperExtensions functions under a single Transaction, so that I can roll all of them back if any one fails.
This involves calls to pre-existing functions, some of which
The answer needs to allow for both predicate calls and multiple connections under a single transaction.
So far I've found two approaches, TransactionScope and IDbConnection.
TransactionScope
using (var transactionScope = new TransactionScope())
{
// Function calls here
transactionScope.Complete();
}
Although this should be available in .Net Core 2.0 to my knowledge, it does not appear to be supported by the Dapper and/or DapperExtensions calls I am using. Running this gives me the following error:
"Enlisting in Ambient transactions is not supported."
I browsed for documentation about whether this is or will ever be possible, but came up empty.
IDbTransaction
DapperExtensions' predicate functions seem to support this, but so far, I can't find any examples of the same transaction being used across multiple connections. A few older posts specifically state that this is a "connection-based" transaction approach, so I'm not sure it's possible.
I'm finding that documentation on DapperExtensions is pretty lean, so if anyone can point me toward some references on how its functions handle transactions in general, that would be very helpful, as well!
This issue was fixed in System.Data.SqlClient v4.5
.