Is it possible to set read-only mode on entities that are loaded using NHibernate's Linq provider?
For example, the following can be done with Session.QueryOver (and I believe with Criteria as well):
Session.QueryOver(Of Foo)().ReadOnly()
Is there an equivilent for Session.Query available?
As stated in the documentation 10.1.2. Loading persistent entities as read-only:
To change the default behavior so NHibernate loads entity instances of mutable classes into the session and automatically makes them read-only, call:
Session.DefaultReadOnly = true;
To change the default back so entities loaded by NHibernate are not made read-only, call:
Session.DefaultReadOnly = false;
So before calling Session.Query...
call Session.DefaultReadonly = true
, because this setting goes to the ISession
not to the Provider on top of it.
if you need read only session, better approach is here: how to create a readonly session in nHiberate?
Session.DefaultReadOnly = true;
- in this case NHibernate will accumulate all updates for entities (call all listeners e.t.c.)
session.FlushMode = FlushMode.Never
in this case NHibernate will not call any listeners, as I know
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With