Skip to content
Learn Netverks

Lesson

Step 26/36 72% through track

migrations-ef

EF Core migrations

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches EF Core migrations: the syntax, APIs, and habits you need before advancing in ASP.NET.

EF Core migrations and tracking behavior cause production incidents—LINQ translation limits matter in reviews.

You will apply EF Core migrations in contexts like: Line-of-business CRUD, reporting databases, and multi-tenant SaaS on SQL Server or PostgreSQL.

Write C# (top-level or Program class), click Run on server—the dev runner uses dotnet build/run on a temp net8 project (requires .NET SDK; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

Migrations capture schema changes as versioned C# files—like Django migrations. They keep databases aligned across dev, staging, and production environments.

Workflow

  1. Install tools: dotnet tool install --global dotnet-ef
  2. Change entity classes or Fluent API configuration
  3. dotnet ef migrations add AddProductTable
  4. dotnet ef database update applies to the database

Migration files

Migrations/
  20240528120000_AddProductTable.cs
  AppDbContextModelSnapshot.cs

Commit migrations to source control—never hand-edit production schema without a matching migration.

Important interview questions and answers

  1. Q: migrations add vs database update?
    A: add generates migration code from model diff; update applies pending migrations to the DB.
  2. Q: Failed migration in production?
    A: Restore backup, fix forward migration, test on staging—avoid silent manual DDL.

Self-check

  1. Which command creates a new migration file?
  2. Should migration files be committed to git?

Tip: Run dotnet ef migrations add after every entity change and commit migration files—never hand-edit production tables without a matching migration.

Interview prep

dotnet ef migrations add vs database update?

add generates migration files from model changes; database update applies pending migrations to the database schema.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Add-Migration vs dotnet ef?
  • Down migration risk?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump