Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get SQL Script using Entity Framework Core(code first)

I'm create a web app using Asp.net core with EntityFramework core, but the Update-Database command no longer has the "-Script" switch. How can I get the sql script? Thanks.

like image 392
Brian Holsen Avatar asked Feb 24 '17 03:02

Brian Holsen


People also ask

What is Entity Framework Core?

What Is Entity Framework Core? Entity Framework Core is the new version of Entity Framework after EF 6.x. It is open-source, lightweight, extensible, and a cross-platform version of Entity Framework data access technology. Entity Framework is an Object/Relational Mapping (O/RM) framework.

What is code first approach in Entity Framework?

Entity Framework Core Code First. Code First. If you have used Entity Framework in the past, you will probably have heard about the Code First approach. Code First workflow begins with classes that describe the conceptual model and then Entity Framework generate a database from that model automatically. Code first approach offers most control ...

How to migrate an EF Core database to another entity framework?

The EF Core packages required for migration will be added with .NET Core project setup. Let’s install the Microsoft.EntityFrameworkCore.Tools package and run the following command in the Package Manager console: This will create the classes for supporting migrations. Now let’s apply those changes to the database.

How to delete table from database using Entity Framework Core code?

Now you can see in the below image that our column is now not accepted a null value. Delete table from database using entity framework core code first approach is so simple you have to remove or comment that table from context file, add migration and then update the database. Now you can see that your table is removed from your database.


Video Answer


1 Answers

Run this command to produce the SQL Script

> dotnet ef migrations script -o fileName.sql

Also there's a powershell command for it too: powershell#script-migration

like image 82
VahidN Avatar answered Oct 19 '22 22:10

VahidN