Dapper & TransactionScope?

前端 未结 1 1730
梦谈多话
梦谈多话 2020-12-23 13:36

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 TransactionSc

相关标签:
1条回答
  • 2020-12-23 14:21

    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
          }
    

    Manual Enlistment

        con.Open();
        using (var scope = new TransactionScope())
        {
           con.EnlistTransaction(Transaction.Current);  
           //update/delte/insert statements here
        }
    

    Details can be found here: Details

    0 讨论(0)
提交回复
热议问题