TagEntity Framework

Visual Studio 2019 EDMX files not updating

On April 2nd, 2019 Microsoft released their newest Visual Studio 2019. As a developer who works with Visual Studio daily, I immediately downloaded the newest IDE and started to use. I enjoyed it from the start and the small UI differences work great. But this post is not about how it works but about a feature that is not working, hopefully yet.

In one of my projects we are still using a database first approach with an EDMX file in Entity Framework. We generate SQL scripts for updating our database and then we update our EDMX file, in a separate C# Class project. We use the normal EDMX database first approach by following the next few steps after updating tables or columns in our development database.

  1. Open EDMX file
  2. Right click file and select ‘Update Model from Database’
  3. I then choose my Database Objects and Settings and Click finish.
  4. Then my EDMX file is updated and I can save my file.

In Visual Studio 2017 saving my EDMX file also updated corresponding files under Model.TT. But with the introduction of Visual Studio 2019 only the .diagram file is being updated. This causes an issue because your new tables and columns are not accessible through Entity Framework Database Context. I struggled with this issue for a while and since Visual Studio had just come out, I could not find much information regarding the issue on the internet. I tried removing the EDMX and recreating it but no effect. It was also not a strategy I wanted to do every time I updated our database.

I finally came across a solution about EDMX not updating in a version of Visual Studio dating back to 2013. I tried it in my solution, and it worked. I now must execute a few additional actions before my EDMX project is successfully updated for use. I hope the following steps will become obsolete once again after a next update of Visual Studio 2019. 

Solution 

I open the sub files of my Model.edmx file which contains files with the following extensions.

  • Model.Context.tt
  • Model.Designer.cs
  • Model.edmx.diagram
  • Model.tt

I right click each of the files with the right click on my mouse and then select ‘Run Custom Tool’. Executing these steps will update all corresponding files so they can be used. I believe only the Model.tt file needs to be used by ‘Run Custom Tool’ but I have decided to run them all in case I missed something. 

Run Custom Tool in Visual Studio 2019 for EDMX files

I hope this will help people that have run into the same issue in Visual Studio 2019 or any other version of Visual Studio. And I hope Microsoft will fix this issue in one of the upcoming updates.

Multiple Active Results

Recently I was creating a new Web Application using Entity Framework Code First principal. After a while I was getting the hang of it when I got an error message which I couldn’t place and had not seen before. It was of the type EntityCommandExecutionException and the Inner Exception said There is already an open DataReader associated with this Command which must be closed first.

Lees verder