问题
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
来源:https://stackoverflow.com/questions/12667634/how-to-create-an-nhibernate-read-only-session-with-fluent-nhibernate-that-doesn