Question

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.

Was it helpful?

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.

OTHER TIPS

The articles you linked are still the way to go. Each SessionFactory is responsible for a single connection (connectionstring) and schema.

There is one special case where ou split the database into multiple with the same schema to load balance. This is called sharding and there is the contrib NHibernate.Shards to deal with it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top