NHibernate 3-TransactionScope与NHibernate事务 [英] NHibernate 3 - TransactionScope vs. NHibernate transactions

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

问题描述

我需要为我的新项目在TransactionScope或NHibernate事务之间进行选择. 什么是更好的?什么时候应该使用TransactionScope? NHibernate交易?

I need to choose between TransactionScope or NHibernate transactions for my new project. What is better? When should use TransactionScope? NHibernate transactions?

推荐答案

它们是不同的东西.

您应该始终在NHibernate事务内完成工作.

You should always do your work inside a NHibernate transaction.

例如,您可以根据需要使用TransactionScope.在涉及多个会话的情况下使用分布式事务.

You can use TransactionScope as needed, for example. to use distributed transactions when there's more than one session involved.

NHibernate事务将自动加入分布式事务,但不会自动创建它们,因此建议的模式是:如果您有TransactionScope,请在其中打开NH事务.

NHibernate transactions will automatically enlist in distributed transactions, but they won't be created automatically, so the recommended pattern is: if you have a TransactionScope, open the NH transaction inside it.

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

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