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

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs