0

My situation is as follows. I'm using entity framework (4.0) in which I have defined a relatively simple model like, let's say, two entities:

  • user
  • transaction

A user can have multiple transactions in this scenario. When generating the database this would result (obviously) in 2 database tables names 'user' and 'transaction'.

The problem is that I want to use the code as a webservice where different companies should have their own environment (read: own users and transactions). A simple solution would be to add a column to both tables like, lets say 'company_id' to identify one user/transactions for companya from the user/transaction from companyb.

What I would like to have is a duplication of the tables like so:

  • compa_user
  • compa_transaction
  • compb_user
  • compb_transaction

This way..all data would be nicely separated and if company a generates a lot of transactions, company b would not notice that the system is getting slow or whatsoever.

My question: is there a way to accomplish this based on entity framework. So, can I have multiple tables representing one entity in my model and switch from table to table depending on which company is connecting to the service.

Any help appreciated!

1 Answer 1

2

If you really want to keep the tables seperate, then a seperate database for each client would be the easiest - only need to change the connection string in EF.

The other benefit of this model (seperate databases) is that the database will scale quite easily as each database could theoretically be on a different database server should the DB ever become the bottleneck.

2
  • I thought of that as well. At the moment a data context is created based on the connection string at the moment an instance of the service is created (or the link is established). Maybe I can change the connectionstring before the context is created but it seems a bit nasty. Nevertheless...it is some approach but I rather have the multi table option but if no solution can be found I will try your solution. Thanks! Sep 21, 2011 at 14:42
  • 1
    Perhaps this will help then: stackoverflow.com/questions/1493554/… Sep 21, 2011 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.