Dapper and Nested Transactions

.net dapper sql-server transactions transactionscope

Question

Is it possible to specify a nested transaction as an IDbTransaction parameter, when using a Dapper method?

I want to commit an inner transaction via Dapper, with all data and associated locks to be released and available only to the outer transaction, with all outer locks still in place before the outer transaction is committed.

See this for a concrete example: http://technet.microsoft.com/en-us/library/ms189336(v=sql.105).aspx

I am using SQL Server 2008, if that helps.

Accepted Answer

Dapper uses ado.net transactions. Also, since many ado.net providers support ambient transactions (TransactionScope), this is usually supported - but requires no extra code. If you can do what you want with ado.net transactions: fine. If you can do what you want with TSQL: fine - just issue the appropriate commands. Really it comes down to: can you do that from ado.net?

It would, for example, be worth trying a stored procedure with explicit transaction inside a connection with the connection's BeginTransaction.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why