交易中的"短小精悍点网" [英] transaction in "dapper-dot-net"

查看:187
本文介绍了交易中的"短小精悍点网"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何DAL是否使用短小精悍点网工具创建的事务。

How to create transaction if DAL is using "dapper-dot-net" utility.

我的C#WinForm应用程序将在网络中使用和数据将保存在中央的SQL Server。

My c# winform application will be used in network and data will be saved in central sql server.

所以,我需要用交易。通过使用短小精悍点网,它可以工作或我必须使用NHibernate的或者一些其他的东西...

so, I require to use transaction. By using "dapper-dot-net", it could work or i have to use Nhibernate or some thing else...

请给我你的评论。

也请让我知道,有没有风险或限制使用此框架,如果我使用存储过程或之后,我将需要改变方式,由于限制。

please also let me know, is there any risk or limitation with this framework if i am using stored procedures or later, i will need to change the approach due to limitation.

感谢

推荐答案

我没有碰到使用存储过程的任何限制,你必须用短小精悍的是,你会与存储过程相同风险的风险

I haven't run into any limitations with using sprocs and the risks you have with dapper are the same risks you would have with sprocs

下面是关于如何使用短小精悍交易一个简单的例子

Here is a simple example on how to use transactions with dapper

using (var connection = Db.GetConnection())
{
     connection.Open();
     IDbTransaction transaction = connection.BeginTransaction();
     try
     {
         var newId= connection.Query<int>(@"Select id from table1 where id=@id", new{id }, transaction).Single();
         connection.Execute(@"INSERT into table1 ...",new {p1, p2}, transaction);
         connection.Execute(@"INSERT into table2 ...",new {p1, p2}, transaction);
         transaction.Commit();
     }
     catch (Exception ex)
     {
         transaction.Rollback();
     }
}

这篇关于交易中的&QUOT;短小精悍点网&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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