📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What is an EF Core migration bundle and when would you use it instead of a SQL script?

Junior Theory Intermediate

🎯 Key points

  • dotnet ef migrations bundle produces an efbundle executable
  • No SDK, source or dotnet-ef on the target; --self-contained removes the runtime dependency
  • Applies only pending migrations, tracked in __EFMigrationsHistory
  • Built in CI from the same commit as the app; run in a release stage or job
  • Idempotent SQL script when DBAs review or change control needs the SQL
  • Both beat Database.Migrate() at start-up (races between instances, app needs DDL rights)
  • Bundle tool version should match the EF Core runtime version

⏱ 30-second answer

dotnet ef migrations bundle builds a single executable (efbundle) that contains your compiled migrations and applies the pending ones to whatever connection string you pass (./efbundle --connection "..."). The target machine needs no .NET SDK, no source and no dotnet-ef tool; with --self-contained -r linux-x64 it does not even need the .NET runtime. It runs migrations idempotently against __EFMigrationsHistory, so it fits a CI/CD release stage or a Kubernetes job. Choose an idempotent SQL script (dotnet ef migrations script --idempotent) instead when a DBA must review and run the SQL, when change control requires the exact statements as an artefact, or when the pipeline cannot reach the database with an executable. Both are better than Database.Migrate() at app start-up.

🗣 Full answer (senior)

How I would answer this in an interview

"A migration bundle is my migrations compiled into one executable. In CI I run dotnet ef migrations bundle --self-contained -r linux-x64 -o efbundle from the same commit as the app, publish it as an artefact, and the release stage runs ./efbundle --connection $CONN before the new app version is rolled out. The target needs nothing installed, and the bundle checks __EFMigrationsHistory so it only applies what is pending.

The alternative is an idempotent SQL script, dotnet ef migrations script --idempotent. I pick the script when a DBA or a change board wants to read and run the exact SQL, or when the deployment agent cannot execute arbitrary binaries against production. The bundle is better when the pipeline is fully automated, because it is one step, it handles migrations that contain C# logic, and there is no copy-paste of SQL between environments.

Either way I avoid Database.Migrate() at start-up: several instances race on the schema, and the running app would need DDL rights. One more detail: keep the dotnet-ef tool version aligned with the EF Core package version, otherwise the bundle build can fail or behave differently."


Bundle vs script

Migration bundle Idempotent SQL script
Artefact Executable .sql file
Needs on target Nothing (self-contained) or the .NET runtime sqlcmd, SSMS or a pipeline SQL task
Human review Harder (inspect via script generation) Easy
Migrations with custom C# Supported Only what was rendered to SQL
Best for Automated CI/CD, containers, Kubernetes jobs DBA-gated or regulated releases
dotnet ef migrations bundle --project src/Infrastructure --startup-project src/Api \
  --self-contained -r linux-x64 -o artifacts/efbundle --force
./artifacts/efbundle --connection "$AZURE_SQL_CONNECTION"

Production example

Moving from start-up Migrate() to a bundle step in Azure DevOps removed [occasional] deadlocks when [four] App Service instances started together, and gave a clear failed stage instead of crashing pods.

🔍 What the interviewer is checking

Checks knowledge of deployment options.

↩ Usually asked after

More in EF Core Fundamentals

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me