如何在 nHiberate 中创建只读会话? [英] how to create a readonly session in nHiberate?

查看:14
本文介绍了如何在 nHiberate 中创建只读会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 nHibernate 中创建只读连接?

Is it possible to creat a readonly connection in nHibernate ?

只读:其中 nHibernate 不会隐式或显式地清除对底层数据库的任何更改.

Read-only : where nHibernate will not flush out any changes to the underlying database implicitly or explicitly.

关闭 nhibernate 连接时,它会自动清除对持久对象的更改.

When closing a nhibernate connection it does automatically flush out the changes to the persistent object.

将刷新模式设置为 never 是一种方法 - 但是可逆的(即某些代码可以重置刷新模式).

Setting the flush mode to never is one way - but is reversable (i.e some code can reset the flush mode).

推荐答案

我想您已经找到了解决方案,将刷新模式设置为从不.是的,它是可变的,但即使不是,代码也可以简单地创建另一个具有不同刷新模式的会话.

I think you've already found the solution, setting flush mode to never. Yes, it is changeable but even if it wasn't, code could simply create another session that had a different flush mode.

我认为适当的解决方案是建议使用session.FlushMode = FlushMode.Never只读,并通过使用连接强制到只有 SELECT 权限(或任何适合您的情况)的数据库.通过允许诸如 ReadOnlySessionFactory.Create() 之类的东西,维护单独的 ISessionFactory 工厂可能会有所帮助.

I think the appropriate solution is to suggest read-only with session.FlushMode = FlushMode.Never and enforce it by using a connection to the database that only has SELECT permissions (or whatever is appropriate for your situation). Maintaining separate ISessionFactory factories might help by allowing something like ReadOnlySessionFactory.Create().

这篇关于如何在 nHiberate 中创建只读会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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