是否有criteria.List(Type)事务管理 [英] Does criteria.List(Type) transaction management

查看:119
本文介绍了是否有criteria.List(Type)事务管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是否(不是CRUD,但只有Read)代码要求我编写事务管理?

Does this (not CRUD, but only Read) code require me to write transaction management?

ICriteria criteria = SessionFactory.GetCurrentSession().CreateCriteria(EntityType);
criteria.List<BaseEntity>();


推荐答案

我不能说我总是这样做,但我会说这个问题很合理。正如你可以只读数据库访问的事务一样,我们可以得到的是:

I cannot say that I do it always, But I would say that this question is pretty reasonable. As you can Transactions for read-only DB access? what we can get is:


如果您希望为默认超时以外的查询设置特定的超时值,或者要更改隔离级别,则只读操作需要事务。

Transaction are required for read-only operations if you want to set a specific timeout for queries other than the default timeout, or if you want to change the isolation level.

正如此处所述: NHibernate读取事务(小提取)

And as mentioned here: NHibernate Transactions on Reads (small extract)


即使我们只读数据,我们也想使用一个事务,因为使用事务可以确保我们从数据库中获得一致的结果。

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.

所以,一般来说,如果你有共同的方法(例如使用AOP的Web请求处理)它可能是有用的

So, in general, if you have common way (e.g. Web request handling with AOP) it could be useful

这篇关于是否有criteria.List(Type)事务管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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