Search code examples
nhibernatefluent-nhibernatenhibernate-3

Multiple database with NHibernate 3.x


I found a couple of articles how to use NHibernate with multiple database, for example this one http://codebetter.com/karlseguin/2009/03/30/using-nhibernate-with-multiple-databases/

But all articles are very old, and may be there is some new approach with NH 3.x? I looked in documentation but did not found anything, but maybe i missed somthing?

Does anybody knows some better way (native NH3.x way) to use NH 3.x with multiple database than described in this article? http://codebetter.com/karlseguin/2009/03/30/using-nhibernate-with-multiple-databases/

Thanks, Alexander.


Solution

  • AFAIK, there is nothing new in NH 3. But there are still more options to use several databases than in the blog post you linked.

    • You can open your own connection and pass it to NH when opening a session.
    • You can open a session and switch to another database on the same server (eg. by executing a use database statement on sql server).
    • You can provide a schema (database) name on each table you map in the mapping file. It is not useful to have it hard coded, but you can still replace it after loading the mapping files or use mapping by code.