DEV Community

Steve Mak
Steve Mak

Posted on • Edited on

18

Cheatsheet for Entity Framework Core

EF Core Command from Package Manager Console (PMC) / .NET CLI

Reference

PMC .NET CLI Usage
Add-Migration Add Creates a migration by adding a migration snapshot.
Remove-migration Remove Removes the last migration snapshot.
Update-database Update Updates the database schema based on the last migration snapshot.
Script-migration Script Generates a SQL script using all the migration snapshots.

Code First

# PMC
PM > Add-Migration InitialCreate
PM > Update-Database
PM > Remove-Migration
PM > Script-Migration

# .NET CLI
> dotnet ef migrations add InitialCreate
> dotnet ef database update
> dotnet ef migrations remove
> dotnet ef migrations script
Enter fullscreen mode Exit fullscreen mode

Database First

# PMC
PM > Scaffold-DbContext 'Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Chinook' Microsoft.EntityFrameworkCore.SqlServer

# .NET CLI
> dotnet ef dbcontext scaffold "Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Chinook" Microsoft.EntityFrameworkCore.SqlServer
Enter fullscreen mode Exit fullscreen mode

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay