Today I have faced a problem when working with a previous developed ASP.NET MVC application. Just copy the database(.sdf) from previous version to new version. I have changed some validation and business logic. But when run the application it shows me the following error:
It was a running application after searching on community I have got the solution.
Solution 1:
However, even if you manually update the database to follow the model, this exception will still occur. The reason is that EF does not check model schema completely: tables, columns, keys, indexes etc.
It calculates a hash of the model and compares with the hash of model which the database was built with. The hash is stored at EdmMetadata table.
The model backing the 'MyDBContext' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.
It was a running application after searching on community I have got the solution.
Solution 1:
However, even if you manually update the database to follow the model, this exception will still occur. The reason is that EF does not check model schema completely: tables, columns, keys, indexes etc.
It calculates a hash of the model and compares with the hash of model which the database was built with. The hash is stored at EdmMetadata table.