After updating Entity Framework model, Visual Studio does not see changes

C#Entity FrameworkEntity Framework-5

C# Problem Overview


If I do any changes to my EF 5.0 model, VS does not seem to see the changes. I have tried adding a new table, which shows up fine in the model, but then if I try to use it somewhere the table does not show up in intellisense and I can't use it.

I have also tried changing datatypes of a column, which again shows up fine if I look at the .edmx model file, but visual studio will still give me compiler errors on that field because I am trying to assign the incorrect datatype.

If I delete the EDMX completely, and recreate it, then the changes work fine. but it is tiresome to regenerate from database each time when I should be able to just "update model from database" and rebuild.

I have never had these problems with EF before. Does anyone know the cause or the fix to this problem?

Thanks.

C# Solutions


Solution 1 - C#

First Build your Project and if it was successful, right click on the "model.tt" file and choose run custom tool. It will fix it.

Again Build your project and point to "model.context.tt" run custom tool. it will update DbSet lists.

Solution 2 - C#

If this is the bug with the edmx file located in a folder it is now fixed - download and install VS 2012 Update 1. You can get it from: http://www.microsoft.com/visualstudio/eng/downloads#d-visual-studio-2012-update

Solution 3 - C#

This is apparently a bug in the Entity Framework that the model does not get updated when your Edmx file is located inside a folder. The workarounds available at the moment are:

  1. Install VS 2012 Update 1 which should fix the bug.
  2. If you are not in a position to install Update 1, you will have to right click on the model.tt T4 template file and click run custom tool. This will update the classes for you.

Hope that helps someone out there.

Link: http://thedatafarm.com/blog/data-access/watch-out-for-vs2012-edmx-code-generation-special-case/

Solution 4 - C#

I also had this problem, however, right-clicking on the model.tt file and running "Custom tool" didn't make any difference for me somehow, but a comment on the page Ghlouw linked to mentioned to use the menu item "BUILD > Transform All T4 Templates." which did it for me

Solution 5 - C#

Right click the .tt file and select "Run Custom Tool", that should update it: see image

Solution 6 - C#

You should have a <XXX>Model.tt file somewhere which is the T4 template that generates your model classes.

If it is in a different project, it will not update when you save the edmx file.

Anyway, try right-clicking on it in Solution Explorer and choosing Run Custom Tool

Solution 7 - C#

I searched for this answer because I had a similar situation in VS2013. In my case, I found that a simple "Clean Solution" cleared out all the old definitions.

Solution 8 - C#

Are you working in an N-Tiered project? If so, try rebuilding your Data Layer (or wherever your EDMX file is stored) before using it.

Solution 9 - C#

I've also experienced this problem with none of the classes being generated under the model.tt file. In my case it was down to issues with how I had built the DB in SQL2012. I'd set a column in a table to nullable that was also a foreign key and although I think you should be able to do this it caused a problem in EF5.

As soon as this was cleared and the diagram updated from the database they reappeared.

EF5 VS2013

Solution 10 - C#

After Changing the laptop When I updating Entity Framework model, stored procedures are not seen in code

What I have done to make this working

  • Update visual Studio 2012 Update 5 (Not Working)
  • Update/Modify from Programs (Not working)
  • After update stored procedures, build the project again then go to context.cs, right click and run custom tool (Not Working)
  • Doing RND (Someone says the issue is due to some permissions in MSSQL) But unfournately I have done alot of permission in MSSQL but (Not Working)
  • Install 2019 and run the project. Now everything works fine

Conclusion

  • Visual studio 2012 have a bug (bug is resolved in Update 1, 2, 3 and 4)
  • Change the Visual Studio version will resolve the issue

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKyleView Question on Stackoverflow
Solution 1 - C#Mahdi ShahbaziView Answer on Stackoverflow
Solution 2 - C#PawelView Answer on Stackoverflow
Solution 3 - C#GhlouwView Answer on Stackoverflow
Solution 4 - C#KristianView Answer on Stackoverflow
Solution 5 - C#Tshilidzi MudauView Answer on Stackoverflow
Solution 6 - C#Nick ButlerView Answer on Stackoverflow
Solution 7 - C#woodviView Answer on Stackoverflow
Solution 8 - C#MiddasView Answer on Stackoverflow
Solution 9 - C#CF5View Answer on Stackoverflow
Solution 10 - C#Adil ShahView Answer on Stackoverflow