NHibernate的交易上读取 [英] NHibernate Transactions on Reads

查看:92
本文介绍了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? ;)

推荐答案

这篇文章从作者之一可能有你的答案:

即使我们只是读取数据,我们
要使用事务,因为使用事务
确保我们从数据库中获取
A一致的结果。
NHibernate的假设为$ B $所有接入B数据库是
事务中完成的,并极力劝阻
没有
事务中的任何使用会话。

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.

撇开
的安全问题,处理事务工作时,
假设交易
昂贵的,我们需要对其进行优化为
A假的。如已经提到的,
数据库总是在
交易运行。和数据库已经
大量优化与
交易工作。现在的问题是什么
这是每个语句或每批次。
有需要
要做创建和配置一个
的交易一定量的工作,而不必做每
语句实际上是比
更昂贵做每批次。

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天全站免登陆