tags:

views:

558

answers:

2

I have a WPF App that is run on the client. I have two different databases the app uses. One that is SQL Server 2008 for the application data and one that is Sql Server Compact for user settings stored on the client. I am using the app.config to configure NHibernate. I've seen a lot of articles using the "schema" attribute in the class mapping file, but that only works if I'm connecting to the same SQL Server. How do I configure NHibernate to be able to set up two different session factories?

I would like to configure this in the app.config file if possible.

A: 

Back before I converted everything to use Fluent NHibernate and dependency injection, my company's NH libraries were configured to use multiple database and it was configurable through app.config (well, web.config in this case). I believe it was using a session manager based off the one in Bill McCafferty's CodeProject article.

If you don't need something as complex, it's largely a helpful wrapper for the following:

Configuration cfg = new Configuration();
cfg.Configure(sessionFactoryConfigPath);
sessionFactory = cfg.BuildSessionFactory();

You could use the above to create your own method for passing in a session factory config file and instantiating your session factory.

Stuart Childs
I read that article and it seemed like there would be a simpler way. I was thinking of something like having multiple <session-factory> tags under the <hibernate-configuration> config section in the app.config each with a name. Then call new Confugration().Configure("name_of_session_factory");.
Wili
Not having tried that, I can't say for sure if it will work exactly like that (though I'm sure it's nearly correct if not completely).
Stuart Childs