How to create an NHibernate read-only session with

2019-09-06 08:34发布

问题:

What configuration options should be used to construct a session that will not accumulate updates, and will always remain read only?

It would seem that replacing the first or second level cache for a read only version might be the answer, how is that achieved using fluent configuration?

回答1:

See how to create a readonly session in nHiberate?

Alternatively you can replace the default Save/Update/Delete event listeners with your own implementations that do nothing

To do so, in your NHibernate configuration you will need to do something like:

Fluently.Configure()
    // your config goes here
    .ExposeConfiguration(
        x => x.EventListeners.SaveOrUpdateEventListeners = 
           new ISaveOrUpdateEventListener[ ]{new NoOpEventListener() } ;
    // etc for other types