[c#] After updating Entity Framework model, Visual Studio does not see changes

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.

This question is related to c# entity-framework entity-framework-5

The answer is


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.


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


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


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


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/


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.


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.


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


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to entity-framework

Entity Framework Core: A second operation started on this context before a previous operation completed EF Core add-migration Build Failed Entity Framework Core add unique constraint code-first 'No database provider has been configured for this DbContext' on SignInManager.PasswordSignInAsync The instance of entity type cannot be tracked because another instance of this type with the same key is already being tracked Auto-increment on partial primary key with Entity Framework Core Working with SQL views in Entity Framework Core How can I make my string property nullable? Lazy Loading vs Eager Loading How to add/update child entities when updating a parent entity in EF

Examples related to entity-framework-5

Entity Framework Join 3 Tables The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception Entity Framework (EF) Code First Cascade Delete for One-to-Zero-or-One relationship Could not load file or assembly Microsoft.SqlServer.management.sdk.sfc version 11.0.0.0 EF LINQ include multiple and nested entities Entity Framework 5 Updating a Record Non-static method requires a target How do I enable EF migrations for multiple contexts to separate databases? After updating Entity Framework model, Visual Studio does not see changes Entity Framework Migrations renaming tables and columns