gpt4 book ai didi

c# - 读取时的 NHibernate 事务

转载 作者:IT王子 更新时间:2023-10-29 04:08:02 25 4
gpt4 key购买 nike

我已阅读有关为什么强烈建议在 NH 中对读取操作使用事务的文档和解释。但是,我还没有完全“相信”它。有人可以在不告诉我 RTFM 的情况下尝试解释一下吗,我已经做过了? ;)

最佳答案

This post from one of the authors可能有你的答案:

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.

关于c# - 读取时的 NHibernate 事务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1657465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com