4

I have an EF 6.13 + MVC 5 website running on Azure and I am trying to use Azure's Deployment Slots which is basically having always 2 (or maybe more) sites running while using the same DB and different versions of the source-code, think of it as Slot1 has current production code and Slot2 has the vNext code.

The issue I'm having is that when there's a migration in Slot2, even if we make it so that compatibility is not affected, then EF will complain about the DB not being in the same version as the Model.

I have read this questions:

but in both cases they ensure EF won't complain about Model compatibility by making it NOT CHECK compatibility at all using some variation of this:

public class MyDBContext: DbContext 
{
    public MyDBContext() : base("myConnString")
    {            
        //Disable initializer
        Database.SetInitializer<MyDBContext>(null);
    }
} 

There is however a few things unclear to me:

  • If I change the Model Compatibility checks and no migrations are run automatically, then how do I migrate my DB?

  • Can I make my DbContext check model compatibility and warn me only if it's broken (like I deleted a column or something like that, not that I added another column, I know this can be troublesome but bear with me and assume I have a plan for these kind of events)

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Luiso
  • 4,173
  • 2
  • 37
  • 60

1 Answers1

0

If I change the Model Compatibility checks and no migrations are run automatically, then how do I migrate my DB?
I have a good answer for you here: Dis-Advantages of using EF 6.x.x Code First without Migration

Can I make my DbContext check model compatibility and warn me only if it's broken (like I deleted a column or something like that, not that I added another column, I know this can be troublesome but bear with me and assume I have a plan for these kind of events)

It is not easy to do that. The problem is that you have to decode the Model on the fly and compare it with Model column of the MigrationHistory table.


This link might be also interesting for you:

https://romiller.com/2012/03/26/dynamically-building-a-model-with-code-first/

https://romiller.com/2013/02/05/extending-and-customizing-code-first-models-part-1/

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Bassam Alugili
  • 16,345
  • 7
  • 52
  • 70
  • Thanks for the quick replay, I've been going over the links you gave me but their goal is not what I'm looking for. I want to different versions of the code "talking" to the same database (which would be in a compatible status). – Luiso Jun 13 '16 at 14:46
  • So you have an application is made for example with EF 4.3 and the other application is made with EF 6 and you have one database? Is that exactly what you want? – Bassam Alugili Jun 13 '16 at 15:08
  • I have two versions of the same app, just a few git-commits different, but some of those commits can have migrations, I'm interested to know if there is a way to have both versions working on the same DB for a short time before they're both on the same version again, few days at most. – Luiso Jun 13 '16 at 15:17