Dapper & TransactionScope?
I just started playing around with Dapper. So far i love it. Does dapper not work with TransactionScope
? I noticed that even if i never call TransactionScope.Complete
then my changes are still committed to the database. If TransactionScope isn't supported now is there any plans in the future to support it? If not then you have to use traditional transaction management (System.Transactions.Transaction)?
Update: I just talked to Sam over Twitter. It开发者_开发百科 should work. I'll update it tomorrow morning (at work) with the details to see if anyone can figure out why my changes were still being committed to the db even when i never called complete.
It was totally my fault and not fully understanding transactionscope. A connection is not automatically enlisted in transactionscope unless you open the connection within the transactionscope:
Automatic Enlistment
using (var scope = new TransactionScope())
{
con.Open();
//update/delete/insert commands here
...
scope.Complete();
}
Manual Enlistment
con.Open();
using (var scope = new TransactionScope())
{
con.EnlistTransaction(Transaction.Current);
//update/delte/insert statements here
...
scope.Complete();
}
Details can be found here: Details
精彩评论