NHibernate 读取事务 [英] NHibernate Transactions on Reads

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

问题描述

我已经阅读了有关为什么强烈建议在 NH 中对读取操作使用事务的文档和解释.但是,我还没有完全购买"它.有人可以尝试解释它而不只是告诉我 RTFM,我已经做过了吗?;)

I have read the documentation and explanation on why it is highly recommended to use transactions on read operations in NH. However, I still haven't totally "bought" into it yet. Can someone take a stab at explaining it without just telling me to RTFM, which I have already done? ;)

推荐答案

作者之一的这篇文章 可能会给你答案:

即使我们只是读取数据,我们想使用事务,因为使用交易确保我们得到来自数据库的一致结果.NHibernate 假设所有访问数据库是在一个交易,并强烈劝阻没有使用会话的任何使用交易.

Even if we are only reading data, we want to use a transaction, because using a transaction ensure that we get a consistent result from the database. NHibernate assume that all access to the database is done under a transaction, and strongly discourage any use of the session without a transaction.

暂且不谈安全问题处理交易,假设交易是成本高昂,我们需要优化它们是一个假的.如前所述,数据库总是在运行交易.并且数据库已经大量优化以配合使用交易.问题是随便这是每个语句或每个批次.有一些工作需要要创建和处置一个交易,并且必须按照声明实际上比按批次进行.

Leaving aside the safety issue of working with transactions, the assumption that transactions are costly and we need to optimize them is a false one. As already mentioned, databases are always running in transaction. And databases have been heavily optimized to work with transactions. The question is whatever this is per statement or per batch. There is some amount of work that need to be done to create and dispose a transaction, and having to do it per statement is actually more costly than doing it per batch.

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

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