Upgrade EF Core 8 to EF Core 10 on .NET 10: fix pending model change errors, migration transactions, dotnet-ef tooling and SQL Server changes.
Entity Framework Core (EF Core) 10 requires the .NET 10 Software Development Kit (SDK) to build and the .NET 10 runtime to execute. You cannot run EF Core 10 on .NET 8 or .NET 9. When you upgrade Larkfield.Claims.Api from .NET 8 to .NET 10 Long Term Support (LTS), you skip EF Core 9 entirely, which means your project absorbs breaking behavioral changes from two major releases at the same time.
Previous lesson: Upgrade ASP.NET Core 8 to ASP.NET Core 10 | Next lesson: .NET 10 Docker Images and CI/CD Pipelines
EF Core 10 aligns its Target Framework Moniker (TFM) directly with .NET 10. You must upgrade your project files, package references, and local command line tools together.
Update all EF Core packages in your project files to version 10.0.0 or later:
xmlCopy
Your global and local dotnet-ef CLI tools must also match version 10. Update your global tool using the following command:
bashCopy
If your repository uses a local tool manifest file located in .config/dotnet-tools.json, update the manifest directly or run:
bashCopy
Common Mistake: Leaving an older dotnet-ef tool installed. When the tool is older than the EF Core runtime, it prints a version warning and some commands can fail. Check the installed version with dotnet ef --version.
If your project multi-targets multiple frameworks, EF Core 10 design-time tools now require the target framework flag. Specify the framework explicitly:
bashCopy
In EF Core 8, your application could run migrations at startup even if your C# entity definitions drifted ahead of your migration snapshot. EF Core 9 introduced a strict guardrail that remains active in EF Core 10: any detected divergence between your entity model and the migration snapshot throws an invalid operation exception during migration execution.
This exception occurs when calling Migrate(), MigrateAsync(), or running dotnet ef database update.
Common causes for model drift include forgotten migration steps, missing snapshots, or non-deterministic data seeding in OnModelCreating. For instance, generating dynamic values inside entity seed configurations triggers model drift on every execution:
csharpCopy
To resolve this issue, supply deterministic static values for all seeded entities:
csharpCopy
If you deliberately manage migrations out of band and must temporarily bypass this validation, suppress the warning in your DbContext configuration:
csharpCopy
Pro Tip: Suppressing PendingModelChangesWarning should only serve as an interim step while debugging legacy migrations. Resolve the missing migration or remove dynamic seeding before releasing to production.
In EF Core 8, developers frequently wrapped MigrateAsync inside an explicit transaction or an execution strategy to protect database initialization.
Starting with EF Core 9, and still in EF Core 10, calling MigrateAsync inside an explicit transaction throws an exception for MigrationsUserTransactionWarning. EF Core now takes its own migration lock to stop two processes from migrating the same database at once, and an outer transaction prevents that.
Remove custom transaction and execution strategy wrappers from your migration startup code.
csharpCopy
Call MigrateAsync directly on your database facade without an outer transaction:
csharpCopy
EF Core 9 initially attempted to run all pending migration files inside a single consolidated transaction. EF Core 10 reverted this, so each migration once again runs in its own transaction.
Upgrading to EF Core 10 introduces several behavioral improvements and structural defaults for Microsoft SQL Server and Azure SQL databases.
First, EF Core 10 defaults to the native json data type when mapping complex collections or JSON documents on Azure SQL and SQL Server databases operating on compatibility level 170 or higher. Earlier releases relied on nvarchar(max).
Second, EF Core 10 changes how parameterized in-memory collections translate into SQL queries. In EF Core 8, querying against an in-memory collection often generated queries utilizing OPENJSON. EF Core 10 now sends the values as separate parameters by default, which gives SQL Server better information when it builds the query plan:
csharpCopy
Third, compiled models now reference value converter methods directly. If your entity models use custom value converters, the converter methods can no longer be private. You must declare these methods as public or internal so the generated code can bind to them.
Finally, EF Core 10 automatically adds an Application Name identifier to the database connection string if one is not present. This helps database administrators identify queries coming from specific application services.
Executing database migrations during application startup inside multi-instance web applications creates stability risks. If your Kubernetes cluster or container host starts several instances of Larkfield.Claims.Api simultaneously, each pod tries to take the EF Core migration lock, and the instances that wait can hit startup timeouts and fail health probes.
Isolate schema execution from application deployment. You can generate a standalone SQL script containing all pending migrations inside your Continuous Integration and Continuous Delivery (CI/CD) pipeline:
bashCopy
Apply this idempotent script using a dedicated deployment step, a database release task, or an ephemeral Kubernetes initialization job before routing traffic to your updated .NET 10 containers.
Update Larkfield.Claims.Api to use EF Core 10 by walking through these practical steps.
Open your terminal and update your global EF Core design tool:
bashCopy
Open Larkfield.Claims.Api.csproj and ensure all EF Core package versions are updated to 10.0.0 or higher.
Search your project for calls to BeginTransactionAsync or CreateExecutionStrategy that enclose MigrateAsync. Replace the wrapper logic so MigrateAsync executes independently:
csharpCopy
Verify your entity configurations do not contain non-deterministic calls like DateTime.UtcNow or Guid.NewGuid() inside HasData().
Check for pending model drift by running a local migration dry run:
bashCopy
If EF Core displays an error regarding pending model changes, inspect the diff and generate a clean migration using dotnet ef migrations add.
In the next lesson, .NET 10 Docker Images and CI/CD Pipelines, you will update your container base images from Debian to Ubuntu 24.04 and configure build pipelines for .NET 10.
Was this lesson helpful?