Search code examples
c#sql-serverentity-frameworkdatabase-first

It's seemingly impossible to entirely replace Entity Framework data model from database


Basically, I have a Sql Server database whose schema changes. When this happens, I have to update the EF data model. This is fine if all I did was add or delete a table: go to the designer, find "Update Model From Database..." from one of the multiple locations it exists and go through the wizard.

Unfortunately, the wizard doesn't just let me replace the whole model from the database. It can also only do one thing at a time. So if I make the unfortunate decision of making multiple schema changes and even worse, forget what I did: I have to do multiple steps of adding, refreshing, and deleting tables from the model.

This is obviously cumbersome. So for a lack of a better procedure, I have to blow away the model and go through all the steps of recreating it from the database. Crap: I left the connection string in the configuration file. Now I have to go delete that and start the wizard over or else it won't generate the same entities class name and now all of my code will break.

Why can't this just blow away the model for me and generate from the database? More importantly, why hasn't anyone else asked this question? What are people doing?


Solution

  • You could write a cmd-script that does it via command-line:

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