none
Model first change database in production RRS feed

  • Question

  • Hi everybody

    If i need to add new attributes to the database in production how do i do that?

    I know of code first migrations, but I'm using model first?

    Thanks
    Jakob

    Friday, March 28, 2014 5:25 PM

Answers

  • >You right click in an open area on the model and select Update Model From Database

    That's not Model-First.  That's Database-First, which is by-far the more common (and robust) workflow. 

    For model-first you

    1) Change the model.

    2) Generate Database from Model, to create a new, empty database

    3) Use SQL Server Data Tools to perform a schema migration from the new database to your target database.

    See: Data Developer Center > Learn > Entity Framework > Get Started > Model First

    Usually you're better off to just use SQL Server Data Tools or SSMS to modify the database schema, and then use the Database-First workflow to update your Model and your generated code.

    David


    David http://blogs.msdn.com/b/dbrowne/

    Monday, March 31, 2014 7:04 PM
  • That's not Model-First.  That's Database-First, which is by-far the more common (and robust) workflow. 

    Well whatever it's being called, no DBA in their right mind would let EF change the database schema in a production environment. One makes the changes at the db level by using T-SQL scripts or  using SQL Server Management Studio.    It's done on a development SQL Server first, and VS and the EF Model points to the db scheme and updates the model. The same changes are made to the production SQL Server by a DBA using scripts or SQL Server Management Studio. When code is moved into production that implements the changes made on the db schema that the EF model represents, there should be no problems.   

    Monday, March 31, 2014 10:56 PM

All replies

  • If i need to add new attributes to the database in production how do i do that?

    Ideally, your development database sever has the same database schemas as the production database sever. You do development work on the development database server. You point the existing EF VB or C# project to the development sever, you load the solution via Visual Studio, and  you go to the EF model in the project. You right click in an open area on the model and select Update Model From Database. You verify the model and that's it. You move your compiled code to the production environment.

    Sunday, March 30, 2014 6:01 PM
  • What about data on the production server? If i do that, will i loose all the data?
    Monday, March 31, 2014 5:01 PM
  • >You right click in an open area on the model and select Update Model From Database

    That's not Model-First.  That's Database-First, which is by-far the more common (and robust) workflow. 

    For model-first you

    1) Change the model.

    2) Generate Database from Model, to create a new, empty database

    3) Use SQL Server Data Tools to perform a schema migration from the new database to your target database.

    See: Data Developer Center > Learn > Entity Framework > Get Started > Model First

    Usually you're better off to just use SQL Server Data Tools or SSMS to modify the database schema, and then use the Database-First workflow to update your Model and your generated code.

    David


    David http://blogs.msdn.com/b/dbrowne/

    Monday, March 31, 2014 7:04 PM
  • That's not Model-First.  That's Database-First, which is by-far the more common (and robust) workflow. 

    Well whatever it's being called, no DBA in their right mind would let EF change the database schema in a production environment. One makes the changes at the db level by using T-SQL scripts or  using SQL Server Management Studio.    It's done on a development SQL Server first, and VS and the EF Model points to the db scheme and updates the model. The same changes are made to the production SQL Server by a DBA using scripts or SQL Server Management Studio. When code is moved into production that implements the changes made on the db schema that the EF model represents, there should be no problems.   

    Monday, March 31, 2014 10:56 PM