达珀TransactionScope? [英] Dapper & TransactionScope?

查看:93
本文介绍了达珀TransactionScope?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始和Dapper一起玩。到目前为止,我喜欢它。 dapper是否不能与 TransactionScope 一起使用?我注意到,即使我从不调用 TransactionScope.Complete ,我的更改仍会提交给数据库。如果现在不支持TransactionScope,将来有计划支持它吗?如果不是,那么您必须使用传统的事务管理(System.Transactions.Transaction)?

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)?

更新:我刚刚通过Twitter与Sam交谈。它应该工作。明天早上(工作时)我将使用详细信息进行更新,以查看是否有人能弄清楚为什么即使我从未打电话给complete,我的更改仍要提交给数据库。

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.

推荐答案

这完全是我的错,并且没有完全了解transactionscope。除非您在transactionscope中打开连接,否则不会自动将其征召到transactionscope中:

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

这篇关于达珀TransactionScope?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆