I am developing an MVC 5 application which is using 2 code first databases and 1 database first. Now I want to deploy and make it available for multiple clients to work. For that matter I want to generate my Database First Database for every new client. My database first database has 103 tables with PKs, FKs and triggers have also been built in them.
My DbContext is as follows:
public partial class MyEntities : DbContext
{
public MyEntities() : base("name=MyEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
** Here are my DbSet's **
}
Now the major concern of mine is that I also want to use MyEntities for accessing the databases for each client. Because my all controllers validations are accessing the database with that entity name as follows:
public MyEntities db = new MyEntities();
Now how could I be able to create a new database for each client and the Context name should remain same so that I don't have to change my code in Controllers? Moreover I also have to pass the InitialCatalogue name as a variable to web.config for each database.