Jim
Jim

Reputation: 16022

How to create an NHibernate read-only session with Fluent NHibernate that doesn't accumulate updates?

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?

Upvotes: 0

Views: 1908

Answers (1)

Martin Ernst
Martin Ernst

Reputation: 5679

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

Upvotes: 3

Related Questions