如何在dapper.net上使用交易? [英] How to use transactions with dapper.net?

查看:51
本文介绍了如何在dapper.net上使用交易?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在多个表上运行多个insert语句。我正在使用dapper.net。我看不到有任何方法可以处理dapper.net上的事务。

I would like to run multiple insert statements on multiple tables. I am using dapper.net. I don't see any way to handle transactions with dapper.net.

请分享您有关如何使用dapper.net上的事务的想法。

Please share your ideas on how to use transactions with dapper.net.

推荐答案

以下代码段:

using System.Transactions;    
....    
using (var transactionScope = new TransactionScope())
{
    DoYourDapperWork();
    transactionScope.Complete();
}

请注意,您需要添加对 System的引用。 Transactions 程序集,因为默认情况下未引用该程序集。

Note that you need to add reference to System.Transactions assembly because it is not referenced by default.

这篇关于如何在dapper.net上使用交易?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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