Gordon Copestake
Gordon Copestake

Reputation: 1647

Convert existing ASP.NET web forms application to multi-tenancy

I have an existing ASP.NET web forms site that uses entityframework to connect to a single SQL database as a datasource.

I've been asked to convert the app to a multi-tenant application to cater for a new client.

The codebase is identical and the easiest way I can see is simply connect the app to a different copy of the database based on a field in the user table.

Questions:

1) where do I store the users? Currently there is a single users table in the existing app, do I need to split this out to a 3rd database that is common between the two tenants?

2) The big one: How do I connect entityframework to a different database depending on a field in the user table? Currently the database is set from web.config. I would like to do this with as little code change as possible!

Upvotes: 0

Views: 1007

Answers (2)

Mike Cole
Mike Cole

Reputation: 14723

If using Code-First, I strong recommend doing this on the global level instead of on each individual query. See https://github.com/jbogard/EntityFramework.Filters.

Upvotes: 1

softilium
softilium

Reputation: 175

I think, in your case multitenancy is just splitter inside each table on your app.

  1. Determine common tables which do not require to split.
  2. Add splitter field to another tables.
  3. Link each user to splitter value.
  4. Add XXX.Where(=>.Splitter=SplitterValue) condition to each EF linq query. May be you can do it globally, but it depends on your architecture.
  5. Rebuild indexes to cover that queries

Upvotes: 0

Related Questions