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.
Nov 12, 2020 First of all create a database (I am using the Northwind database.). Step 1: Create a new Windows Form Application project: Step 2: 'EntityFrameWorkSample' 'Add' 'New Item' 'Data' 'ADO.NET Entity Data Model'. On the other hand write your model name (Model1.edmx is the default name; I do not want to change it) and push the 'Add. Re: Entity Data Model Designer is unable to display the file you requested. Oct 21, 2016 02:49 AM. Cathy Zou LINK. Hi rasikabhairi, From your description, I create a.edmx file in my application, it could be open with the Entity Designer. Then I open it with xml editor, the header of my edmx file like below. After modifying an EDMX in Visual Studio 2019, it saves the EDMX properly but does not generate the C# files. This is a database first functionality, is there a new trick in VS2019 to actually gen.
- Open EDMX file
- Right click file and select ‘Update Model from Database’
- I then choose my Database Objects and Settings and Click finish.
- 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.
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.
As far as I can remember, Visual Studio always had something called “custom tools”, also known as single-file generators. When you apply such a tool to a file in your project, it will generate something (typically code, but not necessarily) based on the content of the file. For instance, the default custom tool for resource files is called ResXFileCodeGenerator, and generates a class that provides easy access to the resources defined in the resx file.
When you save a file that has a custom tool associated to it, Visual Studio will automatically rerun the custom tool to regenerate its output. You can also do it manually, by invoking the “Run custom tool” command in the context menu of a project item.
Usually, the custom tool needs only one input file to generate its output, but sometimes things are a bit more complex. For instance, consider T4 templates : they have a custom tool associated with them (TextTemplatingFileGenerator), so this tool will be run when the template is saved, but in many cases, the template itself uses other input files to generate its output. So the custom tool needs to be run not only when the template is modified, but also when files on which the template depends are modified. Since there is no way to tell Visual Studio about this dependency, you have to rerun the custom tool manually, which is quite annoying…
Because I was in this situation, and was tired of manually invoking the “Run custom tool” command on my T4 templates, I eventually created a Visual Studio extension to do this automatically: AutoRunCustomTool. The name isn’t very imaginative, but at least it’s descriptive…
This tool is designed to be very simple and unobtrusive; it just does its work silently, without getting in your way. It adds a new property to each project item : “Run custom tool on”. This property is a collection of file names for which the custom tool must be run every time this project item is saved. For instance, if you have a T4 template (Template.tt) that generates a file (Output.txt) based on the content of another file (Input.txt), you just need to add “Template.tt” to the “Run custom tool on” property of Input.txt. Every time you save Input.txt, the custom tool will be automatically rerun on Template.tt, which will regenerate the content of Output.txt. You can see a concrete example on the tool’s page in Visual Studio Gallery.
Import Edmx File Visual Studio
I created AutoRunCustomTool about 6 months ago, but the initial version was a bit rough around the edges, so I didn’t communicate about it. I released the second version a few days ago, and I think it’s now ready for everyone to use. If you’re interested in the code, you can find it on GitHub, which is also the place to report issues and suggest improvements.