EF 4.3 CodeFirst MVC3 WebApp and the console use the same model, but for some reason they "see" another model, which leads to a model support error

I use the same model for several applications: the MVC3 web application, Windows services, and the console application. When I run the MVC3 web application, it generates a database. I can restart it, and everything is in order. But when I start the console application, I get an error message:

A model that maintains the "... context" context has changed since the database was created. Consider using First Code Migrations to update your database (http://go.microsoft.com/fwlink/?LinkId=238269).

The same thing happens when I drop the database, start the console application, I can restart it, and everything is fine too. When I launch the MVC web application. Crash: model support ... etc.

In EF4.1, deleting the EdmMeta table "resolved" the problem. But since EF4.3 no longer has such a table, I cannot fix it. I checked that all applications belong to the same dll model. I double-checked that all projects reference EF4.3, so as not to cause the problem.

Any constructive help would be appreciated.

Regards, Erwin Van Dyck

+4
source share
1 answer

You must not allow multiple applications to create a database, which may lead to an unexpected deletion of your database. Just select the one who will be responsible for creating the database and for all other purposes:

Database.SetInitializer<YourContext>(null); 

Also add this to your OnModelCreating in your derived DbContext :

 modelBuilder.Conventions.Remove<IncludeMetadataConvention>(); 

This should avoid hash calculation problems.

Learn more about the reasons why hash computing problems are described here .

+12
source

Source: https://habr.com/ru/post/1397465/


All Articles