question

AmirSaleem-3788 avatar image
0 Votes"
AmirSaleem-3788 asked DanielZhang-MSFT commented

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

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.


dotnet-entity-framework-core
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DanielZhang-MSFT avatar image
1 Vote"
DanielZhang-MSFT answered

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AmirSaleem-3788 avatar image
0 Votes"
AmirSaleem-3788 answered DanielZhang-MSFT commented

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?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @AmirSaleem-3788,
You can try the SQL scripts which can be reviewed for accuracy.
Please refer to this document.
Best Regards,
Daniel Zhang


0 Votes 0 ·