0

My client requirement is to implement application as same application with different database as Multi Tenant application. As per requirement, different user can access same application but as per user identity he will be connecting to different database to access company specific details. each company has different database.

I would be planning this with Asp.Net MVC, EntitiyFramework with database first (as database already exist) but I am not sure will able to handle this as multitenant app. Can you please guide or give me any direction or sample if already implemented.

Thanks Nik

nikudale
  • 399
  • 2
  • 12
  • Good news bad news, using manual sql deploys you will easily be able to code the app by changing the session users dbconnection on db context to do this at runtime. Bad news is EF is not going to be able to code first deploy/migrate for you in any meaningful way. – Paul Swetz Sep 15 '16 at 19:28
  • Thanks for reply but not able to understand. can you please elaborate if possible. – nikudale Sep 15 '16 at 21:33
  • The DBContext constructor takes a connection string (or config connection string name) so changing the database a user is using at runtime is very easy. https://msdn.microsoft.com/en-us/library/system.data.entity.dbcontext.dbcontext(v=vs.113).aspx#M:System.Data.Entity.DbContext. The problem is going to be if you expect to find a way to use automigrations to deploy code first db changes. There is simply no mechanism built in to support targeting multiple databases with a migration. It could be possible but the toolchain to do it would have to be custom developed. – Paul Swetz Sep 16 '16 at 12:53
  • Thanks for reply Paul. so lets 2 clients same code base but diff db and tomorrow one of client want some model changes, can it be possible to configure through db first or code first? – nikudale Sep 16 '16 at 16:14
  • If your client DBs are not exact schema copies then the only way I know of to deal with it is to runtime inject libraries that have the EF models in them that are specific to that client. Your going to end up with one EF project per CLIENT. The whole thing will be a maintenance nightmare. – Paul Swetz Sep 16 '16 at 16:41
  • may be of help http://stackoverflow.com/questions/19458943/multi-tenant-with-code-first-ef6 – Paul Swetz Sep 16 '16 at 17:01

0 Answers0