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

好久不见. 提交于 2019-12-13 04:43:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!