if you use 1 database with tenancy (tables, or views) you can use NH
filters on all queries. here is an example.
http://nhforge.org/wikis/howtonh/contextual-data-using-nhibernate-filters.aspx

if you go with 1 db per customer then you need to build the connection
strings and/or session factories dynamically. i think there is an
article about that either on the nhforge wiki or this user group. i
can't find a link to it though. If I'm not mistaken you can implement
your own connection string builder/factory/object and have NH use
that. then you can have 1 session factory to manage all your
databases.

another option is to use your IoC of choice to build/utilize the
correct session factory on the fly the details of that would depend on
the IoC.

On Nov 17, 4:06 pm, Niclas Pehrsson <[email protected]> wrote:
> I have some questions and thoughts about how to use NHibernate
> efficient in a multi tenancy environment.
> If we look at our business rules we have thousands of customers that
> will run our system. We are hosting it all
> Our system is an economy system and each customer has its own data.
> But in some cases there are other companies that handles several of
> our customer data and we want them to be able to login and have access
> to all these customer data.
> I have seen some solutions on multi tenancy solutions. What I can see
> there are three.
> Multiple databases (one per customer)
> One database with views that has a tenancy id which will make the
> database transparent and in the application make the database seem
> like there are only one customer.
> One database with all data, Solve what the customer shall see or not
> se with Ids in every criteria or linq query
> What is the best choice for me?
> If I use multiple databases which are my favorite right now, we will
> have thousands of databases in our SQL environment; can it be hard to
> manage? In some cases we will have one user that can manage several
> companies, I’m not sure they need to manage them at once, so it maybe
> can be solved in an easy way. How shall we solve the sessionfactory
> problem? The mapping and all settings will be the same for all
> customers but the connection string will differ per customer so, can I
> make an sessionfactory where I can make sessionFactory.OpenSession
> (connectionstring) kind of thing? Or are there some problems with a
> solution like that? The sessionfactory will in this case live in an
> wcf service and an web application.
> Views, are there any tips I need to know about? Any problems with
> NHibernate working with views? Same problem here with the
> sessionfactory, how can I change the connection string per session?
> I don’t even want to think about the third solution

--

You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=.


Reply via email to