How to give script for production when working with Entity Framework corre

Amir Saleem 41 Reputation points

Hi I was working in an environment where we would update the database script for database schema or read-only data in the script, or would use the SQL Project to create the script so that script can be given to update the database in production or to anyone who needs the latest update.
Now for my own little project I started to use the EF Core, which takes the database first approach. And I have questions.

  1. Once the release is done how I can provide the changes to the production.
  2. If there are tables whose sole purpose is read only, what would be the best way to create insert statement or updated statement if something changes in the table. For example a Table Department. This department does not get updated commonly and mostly use for read only.
Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
430 questions
No comments
{count} votes

Accepted answer
  1. Daniel Zhang-MSFT 9,471 Reputation points

    Hi AmirSaleem-3788,

    1. The recommended way to keep database changes in sync with the generated model is to use migration, that is, make changes to the model first, and then use tools to generate code that propagates the changes to the database.
      If you need to re-scaffold the model after database schema changes have been made, you can do so by specifying the -f or --force option.
    2. You can generate a script for the migration.
      Here are some related documents you can refer to.
      Migrations Overview
      Reverse Engineering
      Entity Framework Core tools reference - Package Manager Console in Visual Studio
      Best Regards,
      Daniel Zhang

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    No comments

1 additional answer

Sort by: Most helpful
  1. Amir Saleem 41 Reputation points

    Hi Zhang

    I am trying to figure out the situation such as below.
    Scenario 1.

    1. Developer made some changes to the table , stored procedure or view. Then created a migration script with --Idempotent so this script can be applied in QA environment database. This script would be generated wit the if exits statement. It will create objects if object does not exists.
    2. In the next step stored procedure got changed and developer fixed the stored procedure and checked in the changes.
    3. New script sent to the QA, now this time how the Migration script will not update the stored procedure because it would find the stored procedure exits therefore won't do anything however we would want to change the stored procedure.
    4. List item

    2nd Scenario.
    We used to create the script manfully and also enter the insert statements for read-only tables. For example Departments table does not change very often and we would provide the Insert statement on the script. Now moving into crate the Migraiton script. What would be best place to keep those insert statements?