I have a MVC project hosted in Azure App Services with Azure SQL databases for the data. I have a development, staging/acceptance and production environment (App Service) and as for the databases i have development, staging/acceptance, production and a local DB (mdf). I have 3 publish profiles (1 for each environment).
I (think) to understand that i can use the CTOR of the DbContext class to set a connectionstring from the web.config based on the name:
Ex.
public ApplicationDbContext(): base("DbContextNameThatResidesInWebConfig")
{
// ...
}
If i am not using migrations i am able to do what i want without any issues. When using migrations (since i don't want any data loss when changing my model) i am getting several issues on model creation, i tried using several methods in my above CTOR:
// this is a custom Seeder that inherits DropDatabaseAlways/WhenModelChanges
System.Data.Entity.Database.SetInitializer(new ContractCareSeeder());
// from what i understand, this tells to use the latest migrations applied
System.Data.Entity.Database.SetInitializer(new MigrateDatabaseToLatestVersion<ApplicationDbContext, Migrations.Configuration>());
Configuration.cs:
internal sealed class Configuration : DbMigrationsConfiguration<ApplicationDbContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
}
// seeding method ...
}
But i always receive errors like, "there is already a table called XXX ..." even when i have succesfully executed the Update-Database command in the console it still fails.
I am quite lost in this and can't seem to find what is the best way of handling my scenario. I want to be able to use multiple publish profiles (later on we will use development slots but not now) and there there is also configuration possible. I can see all my connections from my web.config along with update database checkbox but i can't seem to find the right way of configuring everything together...
Can anyone assist me, suggest me or provide any help of any kind? Kind regards!