FluentNHibernate won't merge config-properties with fluently mapped ones?
This is a 2-divided problem:
1) Connection string + fluently connection info.
Let's say I have a connection string I read from a global config such as:
<add key="DbConnectionString" value="Data Source=SomeServer;User ID=SomeUser;Password=SomePassword;Integrated Security=False;Pooling=True"/>
Then in every app I have defined a database to use:
I then would like to configure this in FNH by first setting connection string, and then setting the overriden properties like so:
var fnhCfg = FluentNHibernate.Cfg.Fluently.Configure();
fnhCfg.Database(MsSqlConfiguration.MsSql2005
//Set default values
.ConnectionString(connectionString)
//Set specific values
.ConnectionString(c => c
.Database(DbNameReadFromConfig)
This won't work however since the "specific values" overrides the values in the connection string (thus making everything except Database to null.
2) NHibernate config properties + fluently properties
In config file I have:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory name="MyApp">
<property name="current_session_context_class">managed_web</property>
</session-factory>
</hibernate-configuration>
In code I call:
//After call below the properties from my config file exists in fnhCfg
var fnhCfg = FluentNHibernate.Cfg.Fluently.Configure();
//After call below the properties has been overwritten, and my property current_session_context_class is not to be found any longer.
fnhCfg.Database(<my db config>);
Is this "by design" or is it something that can be implemented further down the road?
Thanks,
Support Staff 2 Posted by James Gregory on 12 Mar, 2010 12:02 PM
What you can do is create an instance of the NHibernate
Configuration
class and pass that intoFluently.Configure
. That will load the values from the config file, then merge it with what you specify in the fluently call.3 Posted by juggernaut78 on 12 Mar, 2010 12:23 PM
According to code base in 1.0.0.631 that is the same behavior when using default Configure().
public class FluentConfiguration
...
(And it did not solve the problem unfortunately). I.e. the .Database() call after I've run Configure([cfg]) seems to reset my nh-properties:
I guess that this (implementation wise) is completely unrelated to issue 1) though?