Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to regenerate EDMX file?

I'm working on a .Net 4.0 project which uses Entity Framework 4. Our underlying data model has changed and I'd like to update the Entity Framework components, specifically the model's EDMX file. Currently I'm doing this task manually and it's both time consuming and error prone.

Is there a way to regenerate the EDMX file automatically?

In addition, I would prefer if the model classes are NOT regenerated, as these have been extended with additional logic. I'm okay with manually editing these classes, I just want an automated way to generate the EDMX file.

like image 602
Mark Micallef Avatar asked Jun 10 '14 07:06

Mark Micallef


People also ask

How do I manually edit EDMX?

edmx file open in Visual Studio, you should be able to simply right-click on a table or a column in the table and choose 'rename'. Once you change the name it will be reflected in the Mapping Details window. Problem is that's editing the entity names and properties, not the underlying SQL tables and columns.

How do I open an EDMX file?

Right-click on your EDMX file, select Open With…, then select XML (Text) Editor. Boom, there is your entire EDMX file as Visual Studio and . Net sees it, in all its XML wonderfulness.

What is an EDMX file?

An . edmx file is an XML file that defines an Entity Data Model (EDM), describes the target database schema, and defines the mapping between the EDM and the database. An . edmx file also contains information that is used by the ADO.NET Entity Data Model Designer (Entity Designer) to render a model graphically.


1 Answers

In the Model Browser or the Model Diagram you can right-click and use the Update Model from Database... functionality. However, this will regenerate the classes, as it should.

I think you should reconsider editing the model classes directly and instead use partial classes to extend their functionality (the generated classes are partial by default).

You can also edit the model template files (.tt file when you expand the .edmx file) to generate them in the way you want. Search for T4 templates to find tutorials regarding this.

like image 117
JuhaKangas Avatar answered Sep 17 '22 13:09

JuhaKangas