Drizin/InterpolatedSql

Example of how InterpolatedSql will work if IDbConnection has Transaction?

Closed this issue · 5 comments

Example of how InterpolatedSql will work if IDbConnection has Transaction?

Hi there, sorry I have encountered an error saying BeginExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized

When my DbConnection goes BeginTransaction(), and it seems not like it :(. Any idea what its complaining?

thanks :)

Please share a small example where the problem can be reproduced.

I have somehow resolved the issue. The resolution was to pass in the transaction parameter.. But here is a small example where its reproduced. It seems like we have to pass in transaction if the connection has an active transaction. Please confirm if this is the correct behaviour :) thanks!

image

Yep, passing the transaction to the extension methods (preferably using named parameter to avoid calling the wrong overload) seems to be the correct way of using transactions in Dapper.
DapperLib/Dapper#713

thanks for the link and the help! :)