0

I realise there are a lot of questions about this on Stack Overflow already, but I believe this is slightly different.

I have a setup of 4 databases on 4 different servers that replicate 4 different environments. Sandbox, Test, User Acceptance Testing and Live. These 4 environments have largely the same schema backing them, however there are some differences between each one (mainly between Sandbox and the others as this is most often changed when testing things).

I need to be able to access all 4 environments using Entity Framework from one web application. Currently this all works perfectly when using it to access Test, UAT and Live. Unfortunately when it comes to Sandbox I get the following error:

System.InvalidOperationException: 'The model backing the 'ServicesContext' context has changed since the database was created.

I understand I am getting this error because the database is different from what is expected, but I was hoping there may be a way to get EF to ignore these changes, since the only parts that I am trying to access are all the same.

The only option I have thought of so far is to individually import each of the databases through EF, but I don't want to have to do that as it means I will have to basically copy code for each of the environments (At least, as far as I can see that's what I would have to do?)

I, personally, am not allowed to change and of the system structures or database schemas, so unfortunately that is not an option.

Any help would be most appreciated.

Zurvæ
  • 610
  • 1
  • 8
  • 23

1 Answers1

0

As mentioned by stuartd in the comments, doing the following resolves the issue:

Database.SetInitializer<ServicesContext>(null);

I placed this in the constructor for my EF Context class.

Zurvæ
  • 610
  • 1
  • 8
  • 23