它是很好的做法,始终用一个TransactionScope在DAL基类? [英] Is it good practice to always use a TransactionScope in a DAL base class?

查看:102
本文介绍了它是很好的做法,始终用一个TransactionScope在DAL基类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个集中了所有的数据库调用code在我的应用程序一个DAL基类。我想,以确保所有的插入/更新/删除操作被包裹在一个事务中,不论其是否被写入的SP或没有。难道是很好的做法,总结我的的ExecuteNonQueryDAL方法在一个TransactionScope或者我会被加入了很多开销分贝的呼叫不需要它。

I have a DAL base class which centralises all the database calling code in my app. I want to ensure that all insert/update/delete actions are wrapped in a transaction, irrespective of whether it was written into the SP or not. Would it be good practice to wrap my 'ExecuteNonQuery' DAL method in a TransactionScope or would I be adding a lot of overhead for db calls that don't require it.

我很高兴,当需要换行多个服务调用使用一个TransactionScope furthur了在用户界面,它实际上只是执行它在SP的水平我不知道的。

I'm happy with using a TransactionScope furthur up the in the UI when required to wrap multiple service calls, it's really just enforcing it at the SP level i'm not sure about.

即时通讯使用.NET 3.5和SQLServer的大多是2008年,一些客户仍然使用2005年 - 希望能尽快结束将这些

Im using .net 3.5 and mostly SQLServer 2008, some clients still use 2005 - hoping to move these over soon.

感谢

推荐答案

Tsansactions(尤其是重量级的如的TransactionScope ,甚至与LTM)主要是踢的时候施加多个操作,其可以跨越多个分贝呼叫

Tsansactions (and in particular heavy-weights like TransactionScope, even with the LTM) mainly kick in when applying multiple operations, which may span more than one db call.

添加事务可以是重要的,但是它改变了查询的性质;你能介绍死锁是最明显的,但你也可以改变的的是断层的方法的副作用。它也可以的修订的一个原本的无意的副作用。它改变了锁定轮廓,它具有不同的系统要求(DTC启用是最明显)。

Adding transactions can be important, but it changes the nature of the query; you could introduce deadlocks being the most obvious, but you could also change an intended side-effect of a method that is faulting. It could also fix an otherwise unintended side-effect. It changes the locking profile, and it has different system requirements (DTC enabled being the most obvious).

所以,不要的懒懒地的添加。

同样,很多只读视图屏幕没有的需要的任何特殊的锁定;赫克,大多数列表/搜索/等不能在任何的的方式,如果你看到了正在进行的交易与幻象/肮脏/不可重复的/ etc数据更改。

Equally, a lot of read-only view screens don't need any special locking; heck, most list/search/etc wouldn't change in any important way if you saw an in-progress transaction with phantom/dirty/non-repeatable/etc data.

个人,回来时,我使用基于SP的code,我没倾向于把事务管理中的SP - 它往往是既容易的的移动更适当到一个更高的水平更先进的故障管理 - 即pretty的除TSQL,这不是任何东西的的要善于程序水暖code之类的。这是很好的基于集合的DML,效果显着。

Personally, back when I was using SP-based code, I didn't tend to put the transaction management in the SP - it is often both easier and more appropriate to move that up to a higher level with more sophisticated fault management - i.e. pretty much anything except TSQL, which isn't intended to be good at procedural plumbing code like that. It is good at set-based DML, obviously.

这篇关于它是很好的做法,始终用一个TransactionScope在DAL基类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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