Can the Entity Framework 4.1 designer “update the model from the database” only for selected objects?

Situation: Sometimes a database schema is not what you consider to be an ideal representation of system information, and you cannot change it. We use the Entity Framework to create a more understandable conceptual model for code in such situations. This means updating the model from the database, and then changing it yourself either through the designer or via the .edmx file directly using a text editor.

Problem: When you update the model from the database, all your carefully made changes are thrown out of the window. This can make adding new entities a real problem, since you are basically forced to do this by editing the .edmx file directly.

Question: Is there a way to force the Entity Framework to update only selected objects from the database? Or can it be said to leave the rest of the model when adding a new object?

Thanks!

+7
source share
2 answers

There is no way to make custom updates with the built-in designer. Also, the designer does not throw away all your changes. Usually this does not affect the conceptual model (except in rare cases when it constantly renames some associations) and comparisons, but it always deletes the storage model and redefines it with the new definition. I worked without any problems with modifications to my conceptual model and displaying and running updates from the database.

The designer works like any other in Visual Studio - touching the generated code (memory model) is not supported. After that, you can no longer use Update from database.

There is a commercial tool that probably supports the best model update - you can try a trial version.

+4
source

If when updating selected objects you have in mind only one or several tables, you can delete these tables from the model and then add them back separately to pull out the change tables, selecting them separately - I often do this as base tables (especially during development).

As a result, you lose any changes manually made by you to these re-added objects after the entity / table has been pulled into the model (i.e., I often rename my navigation properties, and then after each re-import of the table, I need to manually rename them again).

+1
source

All Articles