Updating EDMX in a safe way:
As you have already found, updating from a database does not always correctly modify existing properties.
From our daily use of EDMX updates (100 seconds of updates over 24 months), I would recommend the following sequence for updating EDMX.
Delete existing model and then update:
- Open EDMX Designer
- Ctrl-A to select all
- Delete key to delete all models in the designer
- IMPORTANT: do not save EDMX at this moment if you are under source control! *
- Now right-click and select "Update Model from Database" to re-create the entire model.
- Reconstruction of the project for distribution of changes
This will obviously lose any manual settings that you have made to the model, but manual settings should be avoided whenever possible. This makes the whole process reproducible at any time (which is good).
Important notes:
- If you have automatic saving in Visual Studio, you need to quickly select the update (step 5 above) to avoid automatic saving, saving everything.
- If you are under source control and save EDMX after that, your source will mark all generated files as “deleted”, and updating EDMX again may disable files that are not in the original control !.
- This process will not update any stored procedures. In addition, I found that updating EDMX will also not update stored procedures in which only the return type has changed (still current as EF 6.1.1).
Additional recommendation:
Keep EDMX in a separate library. It also becomes a great place to add additional TT files and partial classes (for example, to extend the functionality of EDMX models). I also post any extension methods for the database context in this library. The migration files are generated in the library, as a result of which all this is perfectly preserved.
April 2015 update
The latest version 4 of Visual Studio 2013 seems to have resolved many problems with TFS. Now we will see the created Visual Studio files, and then return them if they have not changed. The above steps still seem the most secure.
September 2015 update
Using the latest version of VS2013 Release 5, we still have problems if saving happens during EDMX update. You may still be in a state where pending deletes cause your tt files to be deleted from the original control during the update. The secret is to update quickly between steps 4 and 5! :)
Gone Coding May 27 '14 at 9:39 a.m. 2014-05-27 09:39
source share