3

I'm working on a project (web application - ASP.NET MVC) that uses one database. Until now said database kept records for one client, but now I need to convert it to multi-client database. The idea is that we add a column (eg. CompanyId) to each Table in DB and in queries consider only records that have specific CompanyId.

Unfortunately, the project is quite developed right now and adding extra parameter to every service call, every Linq query etc would be really troublesome. I know that it should be approached this way (multi-client) from the beginning and now Im paying for it.

So I have two options:

  1. Single database - the problem is how to tell EF to consider only records with CompanyId = X and not to write Where(i => i.CompanyId == X) in every single Linq query.

  2. One DB = one client - creating one db for each client seems to be pretty good solution, but in our project user can have access to several databases (client can be associated with many companies and is asked to choose in context of which company he wants to work with and he can change it freely). The pronblem is I dont really know how to change connection string at runtime and I dont know if this solution is ok.

Could you please tell me which option is better and how to approach it? Thank you in advance.

ksalk
  • 503
  • 2
  • 12

1 Answers1

0

why don't you have separate but identical schemas for each company. You can then inject the right db context objects based on the company selected. In this way, you can avoid major db redactoring and also avoid the condition on company id.

aquaraga
  • 4,138
  • 23
  • 29