4

I'm using the same model for multiple applications: MVC3 web app, Windows services, and a console application. When I start the MVC3 web app, it generates the database. I can restart it, and everything is fine. But when I start the console application I get an error:

The model backing the '...Context' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).

Same occurs when I drop the database, start console app, I can restart this, and everything is fine too. When I start the MVC web app. Crash: model backing... etc.

In EF4.1 removing the EdmMeta table 'solved' the problem. But since EF4.3 doesn't have such a table anymore I can't fix it that way. I've checked that all apps refer to same model dll's. I've double checked that all projects reference to EF4.3 so that's not the cause of the problem.

Any constructive help would be appreciated.

Regards, Erwin van Dijk.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257

1 Answers1

12

You should not let multiple applications to create the database - that can result in unexpected deletion of your database. Simply choose one which will be responsible for database creation and in all other use:

Database.SetInitializer<YourContext>(null);

Also add this to your OnModelCreating in your derived DbContext:

modelBuilder.Conventions.Remove<IncludeMetadataConvention>();

This should avoid problems with hash computation.

More about reasons why problems with hash computation exist is described here.

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • What happens now 'IncludeMetadataConvention' has been depreciated? – marvc1 Sep 27 '12 at 20:18
  • You don't have to include this "modelBuilder.Conventions.Remove();" now that it has been depreciated. Just do the first step he described. That being said, Thank you Ladislav, that helped me solved my problem. – FAtBalloon Jan 29 '13 at 21:41