Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The current model no longer matches the model used to pre-generate the mapping views

I've recently edited one of models and added some new models to my project. I've typed "add-migration sth" in console and upgraded database. Now when I want to connect to db through my MVC site I get this error:

The current model no longer matches the model used to pre-generate the mapping views, as indicated by the ViewsForBaseEntitySets8f8ed3558b66b3b0b5bd7e2867696566a8a1964469dfa075926133c040704be5.MappingHashValue property. Pre-generated mapping views must be either regenerated using the current model or removed if mapping views generated at runtime should be used instead. See http://go.microsoft.com/fwlink/?LinkId=318050 for more information on Entity Framework mapping views.

I found information that it could be blame of old EF installed, but I think I have the most recent one:

<package id="EntityFramework" version="6.1.2" targetFramework="net45" />

What's wrong? How to fix it?

like image 336
Piotrek Avatar asked Jan 19 '15 16:01

Piotrek


1 Answers

I see that other people also have the same problem.

The solution is described here: https://msdn.microsoft.com/en-us/data/dn469601.aspx

All you have to do, is to right click on file where you have class with DbContext, choose "Entity Framework" from dropdown menu and then click on "Generate Views".

The reason is: the "Views" file doesn't fit to Model, so you have to simply generate it again using option that I've mentioned here.

Update: Above solution requires EF Power Tools which is unfortunately not supported on Visual Studio 2015. At last officially, because you can install it anyway and here is how: http://thedatafarm.com/data-access/installing-ef-power-tools-into-vs2015/

In case the link doesn't work:

  1. Download Ef Power Tools
  2. Downloaded file has *.vsix extension. Change it manually to *.zip
  3. Find extension.vsixmanifest
  4. Add 14.0 version in <SupportedProducts> (identically as other present versions) enter image description here
  5. Reverse all steps, create again *.vsix file
  6. Run it, install on Visual Studio

For now I don't know any other easy way.

like image 93
Piotrek Avatar answered Sep 18 '22 10:09

Piotrek