Cheatsheet for Entity Framework Core

ssmak

Steve Mak

Posted on May 29, 2020

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
💖 💪 🙅 🚩
ssmak
Steve Mak

Posted on May 29, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Cheatsheet for Entity Framework Core
cheatsheet Cheatsheet for Entity Framework Core

May 29, 2020