Skip to content

EF Core

Install CLI

dotnet tool install --global dotnet-ef

# Add to project, needed by the CLI tool
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet add package Microsoft.EntityFrameworkCore.<DatabaseProvider>

CLI Commands

Add a migration

dotnet ef migrations add <MigrationName>

Apply migrations

dotnet ef database update

Remove last migration

dotnet ef migrations remove

List migrations

dotnet ef migrations list

Data Seeding

  • Use HasData in OnModelCreating
  • Create migration, changes are only applied if a migration is created.

  • Data Seeding


Last update: August 5, 2023
Created: May 27, 2023