EF Core Command from Package Manager Console (PMC) / .NET CLI
Reference
- https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/?tabs=vs
- https://docs.microsoft.com/en-us/ef/core/modeling/entity-properties?tabs=data-annotations%2Cwithout-nrt
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
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
Top comments (0)