This cheat sheet lists the most common EF Core commands using both the Package Manager Console (PMC) and the dotnet ef CLI.
| Task | PMC Command | dotnet ef CLI Command |
|---|---|---|
| Add a migration | Add-Migration MigrationName |
dotnet ef migrations add MigrationName |
| Remove last migration | Remove-Migration |
dotnet ef migrations remove |
| Update database | Update-Database |
dotnet ef database update |
| Update to specific migration | Update-Database MigrationName |
dotnet ef database update MigrationName |
| Drop the database | Drop-Database |
dotnet ef database drop |
| List migrations | Get-Migrations |
dotnet ef migrations list |
| Apply pending migrations | (PMC uses Update-Database) |
dotnet ef database update |
| Generate SQL script | Script-Migration |
dotnet ef migrations script |
| Script to a specific migration | Script-Migration From To |
dotnet ef migrations script FromMigration ToMigration |
| Reverse engineer (Scaffold) | Scaffold-DbContext |
dotnet ef dbcontext scaffold |
| Get database info | N/A | dotnet ef dbcontext info |
| List DbSets in context | N/A | dotnet ef dbcontext list |
| Get context's connection string | N/A | dotnet ef dbcontext info (includes this info) |
dotnet efmust be run from the project folder, or use--projectand--startup-projectto specify paths.- Reverse engineering example:
dotnet ef dbcontext scaffold "your_connection_string" Microsoft.EntityFrameworkCore.SqlServer -o Models