Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a configuration property when using fluent nhibernate?

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?

like image 703
Sergey Aldoukhov Avatar asked Jun 09 '09 07:06

Sergey Aldoukhov


1 Answers

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();
like image 104
Romain Verdier Avatar answered Sep 20 '22 02:09

Romain Verdier