Question

I am very new in MVC trying to expand my asp.net knowledge after almost 6+ years working with web forms.

MVC is really abstract to me so far but what I like is the clean coding used. I am reading "Pro ASP.NET MVC 3 Framework" book and now I am stuck at one point and I don't know how to continue honestly.

Here is the error I am getting:

The model backing the 'EfDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database.

That happen after I tried updating one Product. The page posted back but nothing got updated in the DB.

Browsing the web I found this temp solution, putting this line in the global.asax file solved the problem: Database.SetInitializer<SportsStore.Domain.Concrete.EFDbContext>(null); but now blank pages are coming up instead pages filled up with data.

I would like to know how I can move forward what exactly do I need to do to fix this.

Was it helpful?

Solution

There are many blogs and articles online explaining migrations, I would use the following two links as reference. In short, you've changed your model, but the tables in your database haven't been updated yet. You can either delete the tables in your database, and allow EF to recreate them, undo the changes to your models, or (MVC 4 only?) run a "migration", which is more or less a fancy way of saying allow EF to create an SQL script to update your SQL tables to match the current version of your model.

http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx

http://coding.abel.nu/2012/03/ef-migrations-command-reference/

OTHER TIPS

Using code first the database has a checksum table to track the change of your classes (called EdmMetaData), and your error shows that Entity Framework has detected a such change. If you want to handle it manually, delete the mentioned table, and update the database manually to conform the class specifications.

The other way, as you mentioned, to let the framework delete and recreate the changed tables.

See the chapter 4 in the Pluralsight video tutorial for a detailed explanation and demo.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top