It seems impossible to completely replace the Entity Framework data model from the database

Basically, I have a Sql Server database whose schema is changing. When this happens, I have to update the EF data model. This is normal if all I did was add or remove a table: go to the designer, find "Update model from database ..." from one of several places where it exists, and go through the wizard.

Unfortunately, the wizard does not just allow me to replace the entire model from the database. He can also do only one at a time. Therefore, if I make an unsuccessful decision to make several changes to the scheme and even worse, forget about what I did: I need to take several steps to add, update and delete tables from the model.

This is obviously cumbersome. Therefore, due to the lack of a better procedure, I have to blow off the model and go through all the steps to recreate it from the database. Crap: I left the connection string in the configuration file. Now I need to delete this and run the wizard, otherwise it will not generate the same entity class name, and now all my code will break.

Why can't it just blow away the model for me and produce from the database? More importantly, why has no one else asked this question? What are people doing?

+8
c # sql-server entity-framework
source share
3 answers

You can write a cmd script that does this through the command line:

http://msdn.microsoft.com/en-us/library/bb896270.aspx

+1
source share

If you want to blow away and replace the model, the easiest way is to simply delete it and recreate it. However, if you made any adjustment to the model, you will of course lose it too.

As a workaround, to allow continuous incremental schema changes (and the changes applied at both ends), I wrote a utility that compares the database with the SSDL level of the EF model, and SSDL with the CSDL level, displays the differences and allow individual (or all ) differences.

enter image description here

You can see it in action here: http://www.youtube.com/watch?v=doqYOlcEAZM ... and if you want to try, you can download it from http://huagati.com/edmxtools/

+4
source share

Your two requirements contradict each other. You want to blow up the whole model, but at the same time you want to keep your setup. The first situation was possible in the Linq-to-Sql designer, but every change was lost every time you updated the model. For EF Designer, MS decided to use the second approach, when the developer almost never touches anything that already exists in your CSDL spaces (entities), but only changes the storage model, and you have to slightly modify the model (in the designer) manually after some changes. I used both designers and I must say that the performance and usability of the second approach are much better. This is also the reason why people usually do not complain about it.

Those who complain usually do:

  • Buy some tool (for example, different from @Kristofer), because MS completely missed everything related to merging changes at different levels of detail, and in the near future it will not be better.
  • Write a script or a custom tool that will return all changes every time the entire model is deleted (this was the way we used with Linq-to-sql).
  • Do not use constructor and support XML manually
  • Switch to code display instead of EDMX
0
source share

All Articles