Reputation: 2044
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.
Upvotes: 4
Views: 12757
Reputation: 3288
You might also want to have a look at this answer. It does exactly as you describe in your question. Configure NHibernate hibernate.cfg.xml file to have more connection strings
Upvotes: 0
Reputation: 1128
Have a look at this great article: Using NHibernate with multiple databases
Upvotes: 5
Reputation: 3305
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.
Upvotes: 0