Reputation: 103517
If my application spans multiple databases, i.e. users 1-10K on server1, 10-10K on server2 (for example), how can I modify my session object to point the correct database?
From what I understand, if I change the connection string in nhibernate's session it will effect everyone and not the current request correct?
Upvotes: 1
Views: 1300
Reputation: 122654
You can only have one connection at a time in one session. To have more would lead to distributed or even ad-hoc transaction semantics, which NHibernate in its basic form doesn't support.
If you're using NHibernate, you're probably using SQL Server, and this sounds like the perfect candidate for linked servers and views. You could have one "main" database with views that consolidate data from all of the different databases. In fact, this is a pretty standard approach to table partitioning, the only difference being that your base tables are in different databases.
Upvotes: 2
Reputation: 1038850
In NHibernate it's the ISessionFactory
which is responsible to hold connection string to a specific database and create ISession
instances. For multiple database support you may take a look at NHibernate Shards which is still work in progress.
Upvotes: 2