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

Resources


Last update: August 11, 2023
Created: June 3, 2023