locked
Update Database From Model RRS feed

  • Question

  • Hello to everyone

    Please can you share with me your thoughts on ways to update my database when I decided to update my EF4 data context model.

    by developing using an itereative process, I only add entities to the EF4 gui as they are needed. This means I need to generate scripts and recreate my database. This means any data is lost as  completely new database has to be created.

    Is there any way I can generate an update script? Or a way to tell EF4 to update the database for me?

    Thanks

    • Moved by VMazur Monday, June 21, 2010 10:21 AM (From:ADO.NET Managed Providers)
    Saturday, June 19, 2010 5:17 PM

Answers

  • Hello,

    Each time you modified your entity model, you could right click the designer (EF4 gui) and select Generate Database from Model. It then will produce a sql script file (with .sql extension) for you. You could execute the sql script the last time it is modified.

    Best regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Wednesday, June 23, 2010 10:44 AM

All replies

  • Hello,

    Each time you modified your entity model, you could right click the designer (EF4 gui) and select Generate Database from Model. It then will produce a sql script file (with .sql extension) for you. You could execute the sql script the last time it is modified.

    Best regards


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have any feedback, please tell us.
    Welcome to the All-In-One Code Framework!
    Wednesday, June 23, 2010 10:44 AM
  • I don't think you answered the question that was asked.  If you have a production database with data in it, and then subsequently generate the database from the model, the script will contain statements to drop the tables, thus removing all production data.  What I would really like is for the script to be generated in a non-destructive, additive way, e.g. if a table doesn't exist, create it.  If it has doesn't have this column, add it....  such that later versions of the script would update the schema without destroying data. 

    From my limited understanding, it looks like model-first development is really limited at this point, not just because of this issue, but because the designer seems to choke (output invalid edmx) whenever you add new associations, etc... to an existing model (at least that is my experience).

    Based on what I have seen so far, the best approach seems to be to evolve your DDL scripts by hand in a non-destructive way and then regenerate the model whenever necessary.  Am I fundamentally missing something?  What are the plans for adding some parity ot model first development?  For people looking to evolve their schemas in the way I describe, is the solution to use the "data dude" stuff (arghhh - yet something else to learn :-)).

     

    thx,

     

    Tony

    Monday, July 5, 2010 12:08 AM
  • Hey, microsoft guys do you have no answer.

    Without an update feature preserving the data of the database the model-first approach isn't usable.

    Sunday, December 5, 2010 1:16 PM
  • Hey, microsoft guys do you have no answer.

    Without an update feature preserving the data of the database the model-first approach isn't usable.

    If you want to generate incremental diff-scripts, take a look at the Model Comparer for EFv4 in my add-in for VS2010, Huagati DBML/EDMX Tools. It can do incremental changes across all three layers; CSDL => SSDL => DB or DB => SSDL => CSDL. You can download it and get a trial license at http://huagati.com/edmxtools/

    I have posted a couple of screencasts etc showing how it works here:
    http://huagati.blogspot.com/2010/07/introducing-model-comparer-for-entity.html
    http://huagati.blogspot.com/2010/08/using-model-comparer-to-generate.html


     
       Cool tools for Linq-to-SQL and Entity Framework 4:
     huagati.com/dbmltools - Rule based class and property naming, Compare and Sync model <=> DB, Sync SSDL <=> CSDL (EF4)
     huagati.com/L2SProfiler - Query profiler for Linq-to-SQL and Entity Framework v4
    Monday, December 6, 2010 9:47 AM