Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force ADO.NET Entity Framework to regenerate code?

I've run into a snag with a ADO.NET Entity Framework model and a ADO.NET Data Service that is making it available. The model and data service are compiling without any problems or warnings when they come out of source control. However when I run the service I get the following error: Request Error - The server encountered an error processing the request.  See server logs for more details.

Unfortunately there are no server logs (that I am aware of) since this is VS 2008 web dev server and there really isn't any code to debug..... Through some trial and error it would appear that the generated code (model.Designer.cs) is out of date in some manner. If I perform some trivial update to the EDM that forces it to regenerate the code file, when I rerun the service it works just fine.

I've tried to delete the model.designer.cs file in the hopes that during the build the project/entity builder would detect the missing file and regenerate it for me. That didn't happen..... Does anyone know how to force this code to be regenerated? (It would also make me a bit happier about not having to keep generated code under source control.)

Thanks

like image 539
Ken Henderson Avatar asked Jan 23 '09 18:01

Ken Henderson


People also ask

What is EDMX file in C#?

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.

How do I update an entity in EDMX?

For updating right click on the edmx icon on Model Browser and select Update Model From Database. This will open a new window where you can see three tabs. Add, Refresh, Delete. If you would like to add a newly created entity then select Add.


2 Answers

Right click on the EDMX file and select Run Custom Tool.

There is also a command line code generation tool called edmgen (available from a VS Command Prompt).

like image 167
Andrew Peters Avatar answered Oct 06 '22 03:10

Andrew Peters


In Visual Studio 2017, it looks like just saving the .tt file automatically re-runs the template, updating the entity class files.

like image 28
Dov Avatar answered Oct 06 '22 05:10

Dov