This seems to work:
Code:
public ISession Session
{
get
{
if (session == null)
{
cfg = new NHibernate.Cfg.Configuration();
// Read mapping classes from assembly
cfg.AddAssembly(mappingFile);
// Create session factory and open session
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AppSettingsSection nhibernateSection = config.GetSection("nhibernate") as AppSettingsSection;
cfg.SetProperty("hibernate.connection.connection_string_name", nhibernateSection.Settings["hibernate.connection.connection_string_name"].Value);
factory = cfg.BuildSessionFactory();
session = factory.OpenSession();
session.FlushMode = FlushMode.Commit;
}
else if (session.IsOpen == false)
{
session = factory.OpenSession();
}
return session;
}
set
{
session = value;
}
}
I.e. setting the property explicitly. Doesn't look very nice though. Cannot NHibernate re-read the settings on its own?