How to set a configuration property when using fluent nhibernate?

徘徊边缘 提交于 2019-12-06 02:10:34

问题


In particular, I'd like to set current_session_context_class. I know how to do it in hibernate.cfg.xml, but is it possible at all with pure fluent configuration?


回答1:


You can use the method ExposeConfiguration on a FluentConfiguration instance, to access the original NHibernate Configuration object.

Then, you'll have access to the Properties property, and you will be able to add the current_session_context_class one.

Here is a the pseudo-code:

Fluently.Configure()
   .Database(SQLiteConfiguration.Standard.InMemory)
   .ExposeConfiguration(c =>
                        {
                          c.Properties.Add("current_session_context_class", 
                                           typeof(YourType).FullName);
                        })
   //.AddMapping, etc.
   .BuildSessionFactory();


来源:https://stackoverflow.com/questions/968730/how-to-set-a-configuration-property-when-using-fluent-nhibernate

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