Reputation: 2788
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.
Upvotes: 8
Views: 15477
Reputation: 41
There is no automatically refresh the EDMX (it will be nice from MS if they implement that at some point) and the best and most accurate way to refresh the EDMX is by deleting all tables in the Diagram and then deleting all complex types etc. in the Model Browser. After that regenerate the EDMX by right click on the Diagram then click on Update Model from Database...
I will not suggest expanding on .tt files though as they will be gone the next time you regenerate the EDMX classes, rather have a model project or a DTO project where you can handle reflecting the EDMX properties and do your manipulation for your data there.
Upvotes: 2
Reputation: 883
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.
Upvotes: 14