Thomas.Benz Thomas.Benz - 1 month ago 13
C# Question

Is code first migration automatically run on the server?

I am very familiar with Entity Framework using Database First approach and how to deploy the solution with it.

Basically, in my solution with database first approach, I have a web client project that consumes data access library project that is coded with database first approach.

So, first, I write some SQL Server scripts to add new tables (or make schema changes).

Next, go to the data access library project, using EF edmx designer to update .net from existing database, compile this data access layer, and the DDL reference is automatically updated in the client web project.

When I deploy the solution to the production server:


  1. First, I need to run the t-SQL scripts on the the production SQL server

  2. Next, I deploy the 2 updated DDLs (one for the web and 1 for the data access layer) on the web server.



Now, I have a new application that includes a web project and a data access layer project that uses EF Code First approach.
I am new to EF code first approach. I know any time when I change the database schema, for instance adding a new table, I need to run code first migration in the Package Management Console in Visual Studio to let my back-end database instance change/update.

My question:

When I deploy the application to the production, what are the steps I should follow?

How is the production SQL server updated that is created with EF Code First approach?

Is it a automatic process or I have to run the migration manually like I do inside Visual Studio under the Package Management Console?

Thanks.

Answer

If you're using Azure then you can configure it has automatic process as shown below.

enter image description here

Else you have to do it manually like this :

You have to create a db script and after that you can run it on your production db.

PM> Update-Database -Script

You can refer this doc : Getting a SQL Script