Hibernate version: 2.0 RC1
I want to programmatically change my NHibernate configuration which I've put in the app.config file.
My app-config looks like this:
Code:
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate, Version=2.0.0.3001, Culture=neutral, PublicKeyToken=aa95f207798dfdb4"/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">...</property>
<property name="connection.isolation">ReadCommitted</property>
<property name="default_schema">...</property>
<mapping assembly="...."/>
</session-factory>
</hibernate-configuration>
Simple. When I configure NHibernate, this all works. My application runs etc...
Now, I want to build some functionality in where I can change these configuration values at runtime.
Therefore, I do this:
Code:
Configuration config = ConfigurationManager.OpenExeConfiguration (ConfigurationUserLevel.None);
object section = config.GetSection(CfgXmlHelper.CfgSectionName);
Then , I want to cast the section object to an object that implements IHibernateConfiguration, but this does not work.
In fact, the GetSection method that I call, returns a DefaultSection object instead of the appropriate NHibernate config object.
When I change my code, so that I call the static GetSection method of the ConfigurationManager, I do get the correct result.
So, the code below works:
Code:
section = ConfigurationManager.GetSection (CfgXmlHelper.CfgSectionName);
IHibernateConfiguration hc = section as IHibernateConfiguration;
But, by working in this way, i cannot save my settings offcourse.
Any suggestions ?