After the update from EF 5.0 to EF 6 Alpha 2, our method for DB checking no longer works.
```
try
{
logger.Info("Check if database migration is required");
var context = new MyContext();
logger.Info("No database migration is required");
}
catch (InvalidOperationException ex)
{
// "The model backing the 'MyContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269)."
if (ex.Message.Contains("The model backing the 'MyContext' context has changed since the database was created."))
{
logger.Info("Redirect all requests because database migration is required!");
ActivateMaintenanceScreenRoute();
}
else
{
throw;
}
}
```
Have you changed anything on the migration needed detection?
Comments: DbContext in all versions of EF is lazy, meaning that it doesn't do very much when an instance is created, but rather only initializes itself the first time that it is used. The exception about the model changing comes from a database initializer, and this is only run when the context is initialized--that is, when it is used for the first time. This means that the code above would only throw if something inside the MyContext constructor actually uses the context for something. This behavior hasn't been intentionally changed between EF5 and EF6. Given this explanation, can you please provide some more info on what is being done inside the MyContext constructor? We will need this information before we can investigate any further. Thanks, Arthur
```
try
{
logger.Info("Check if database migration is required");
var context = new MyContext();
logger.Info("No database migration is required");
}
catch (InvalidOperationException ex)
{
// "The model backing the 'MyContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269)."
if (ex.Message.Contains("The model backing the 'MyContext' context has changed since the database was created."))
{
logger.Info("Redirect all requests because database migration is required!");
ActivateMaintenanceScreenRoute();
}
else
{
throw;
}
}
```
Have you changed anything on the migration needed detection?
Comments: DbContext in all versions of EF is lazy, meaning that it doesn't do very much when an instance is created, but rather only initializes itself the first time that it is used. The exception about the model changing comes from a database initializer, and this is only run when the context is initialized--that is, when it is used for the first time. This means that the code above would only throw if something inside the MyContext constructor actually uses the context for something. This behavior hasn't been intentionally changed between EF5 and EF6. Given this explanation, can you please provide some more info on what is being done inside the MyContext constructor? We will need this information before we can investigate any further. Thanks, Arthur