Upgrading EF Core from .NET 6 to .NET 8 and 10: the breaking changes that actually bite
.NET 6 went out of support in November 2024, and .NET 8’s support ends in November 2026. If you’re still upgrading, the sensible target is now .NET 10, the current long-term support release. EF Core versions are tied to .NET versions, so jumping from .NET 6 to .NET 10 means jumping four EF Core versions at once: 7, 8, 9 and 10. Each one has breaking changes, and on a typical enterprise SQL Server estate a handful of them reliably cause failures.
This article covers the ones that actually bite, roughly in the order you’ll hit them.
1. “The certificate chain was issued by an authority that is not trusted”
This is the one almost everyone hits first. The app worked yesterday on .NET 6, you upgrade, and every database call fails with:
Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established
with the server, but then an error occurred during the login process.
(provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)
What changed
EF Core 7 moved to a newer Microsoft.Data.SqlClient, which (from version 4.0) changed the default of the Encrypt connection string setting from False to True. Every connection is now encrypted with TLS, and the client validates the SQL Server’s certificate like a browser validates a website’s. If the server has a self-signed certificate (which SQL Server generates automatically if none is configured), or a certificate from a CA the app server doesn’t trust, validation fails.
EF Core can’t revert this. It’s the driver, and it’s a deliberate security default. The same thing happens without EF Core if you move Dapper or ADO.NET code from the deprecated System.Data.SqlClient to Microsoft.Data.SqlClient.
The quick fix, and why it’s only a stopgap
You’ll see this fix everywhere:
Server=sql-prd-01;Database=Orders;Integrated Security=True;TrustServerCertificate=True
TrustServerCertificate=True keeps the connection encrypted but skips checking who you’re talking to. That means it doesn’t protect against a man-in-the-middle, which is the whole point of the certificate. The other option, Encrypt=False, turns encryption off altogether. Both get you back to where .NET 6 was, but neither is where you want a production system, and certainly not one handling financial or personal data.
The proper fix
Azure SQL Database and Managed Instance already present certificates from a public CA, so they work with Encrypt=True out of the box. If you’re seeing this error against Azure SQL, check for something in between, like a proxy or an IP address in place of the server name.
On-premises SQL Server is where the work is:
-
Give each SQL Server a certificate issued by your internal CA (Active Directory Certificate Services or similar), with the server’s fully qualified name, and, for an Always On availability group, the listener name, in the Subject Alternative Names. Configure it in SQL Server Configuration Manager and restart the service.
-
Make sure the app servers trust that CA. Domain-joined Windows servers usually already trust the enterprise root through Group Policy. Linux containers don’t: the root certificate has to be added to the image.
# Trust the internal root CA inside a Linux container COPY certs/contoso-root-ca.crt /usr/local/share/ca-certificates/ RUN update-ca-certificates -
Connect using a name that’s on the certificate. If you connect by IP address, a DNS alias or an old server name, validation fails even with a perfectly good certificate. Either connect with the certificate’s name, or tell the client which name to expect:
Server=10.20.30.40;Database=Orders;Integrated Security=True;Encrypt=True;HostNameInCertificate=sql-prd-01.corp.contoso.com
For local development with LocalDB or SQL Server in Docker, TrustServerCertificate=True is fine. Keep that in appsettings.Development.json or user secrets so it never leaks into a higher environment:
// appsettings.Development.json: local only
{
"ConnectionStrings": {
"Orders": "Server=(localdb)\\MSSQLLocalDB;Database=Orders;Trusted_Connection=True;TrustServerCertificate=True"
}
}
Two related surprises:
- Very old SQL Servers that only support TLS 1.0 or 1.1 can’t negotiate a connection from modern .NET on Linux at all, because OpenSSL refuses those protocol versions. The fix is patching or upgrading SQL Server, not weakening the client.
Encrypt=Strict(SQL Server 2022 and later) goes one step further, using TDS 8.0 and always validating the certificate. It’s worth adopting once your certificates are in order.
2. Saving to a table with a trigger fails
Enterprise databases often have audit or history triggers. After upgrading, saving changes to those tables fails with:
The target table 'Orders' of the DML statement cannot have any enabled triggers
if the statement contains an OUTPUT clause without INTO clause.
EF Core 7 started using SQL Server’s OUTPUT clause to read back generated values (identities, defaults, row versions) in the same statement as the insert or update. It’s faster, but SQL Server doesn’t allow a plain OUTPUT clause on a table that has a trigger. Tell EF Core about the table and it falls back to the older approach for that table only:
// EF Core 8 and later
modelBuilder.Entity<Order>()
.ToTable(tb => tb.UseSqlOutputClause(false));
// EF Core 7 used this instead:
// .ToTable(tb => tb.HasTrigger("trg_Orders_Audit"));
Some computed columns cause the same error, with the same fix. To find every table that needs it, list the triggers in the database:
SELECT OBJECT_NAME(parent_id) AS TableName, name AS TriggerName
FROM sys.triggers
WHERE parent_class = 1 AND is_disabled = 0
ORDER BY TableName;
3. Queries with Contains fail or slow down
This one is common on databases that were restored from older SQL Server versions and never had their compatibility level raised. A query like this:
var orders = await db.Orders.Where(o => ids.Contains(o.Id)).ToListAsync();
used to embed the values in the SQL as IN (1, 2, 3). EF Core 8 sends the list as a single JSON parameter and unpacks it with OPENJSON. That gives SQL Server one reusable query plan instead of a new plan for every different list, but OPENJSON needs SQL Server 2016 or later and a database compatibility level of at least 130. On a lower level, the query fails with a syntax error near $ or OPENJSON.
Check the compatibility level:
SELECT name, compatibility_level FROM sys.databases;
Then either:
-
Raise the compatibility level to match your SQL Server version. This is the best fix, but it changes the query optimiser’s behaviour too, so test it like any other change, or
-
Tell EF Core about the older level, so it keeps generating the old SQL:
options.UseSqlServer(connectionString, sql => sql.UseCompatibilityLevel(120));
Even on a modern database, a minority of OPENJSON queries can be slower than before. You can switch back for a single query with EF.Constant:
var blogs = await db.Blogs.Where(b => EF.Constant(names).Contains(b.Name)).ToListAsync();
EF Core 10 changes this again. By default it now sends one parameter per value, IN (@ids1, @ids2, @ids3). That avoids OPENJSON entirely, so the compatibility-level problem goes away on EF Core 10. If you need a particular behaviour, you can set it globally with UseParameterizedCollectionMode or per query with EF.Constant, EF.Parameter and EF.MultipleParameters.
4. Migrations that worked now throw
EF Core 9 made migrations stricter in two ways that catch out a lot of upgraded projects.
It refuses to migrate when the model doesn’t match the migrations. Migrate(), MigrateAsync() and dotnet ef database update throw a PendingModelChangesWarning exception if your model has changes that no migration covers. Common causes in older projects:
- Non-deterministic seed data:
HasDatausingDateTime.Now,DateTime.UtcNoworGuid.NewGuid(). Every build looks like a model change. Replace them with fixed values and add a migration. - A missing or stale model snapshot, usually from hand-written migrations. Add a new migration to regenerate it.
- Genuine drift: someone changed the model and never added a migration. The exception has found a real bug.
# See what EF thinks has changed
dotnet ef migrations add CheckForDrift
# An empty migration means the warning was a false alarm; delete it.
It won’t run migrations inside your own transaction. Code that wrapped MigrateAsync in an explicit transaction now throws MigrationsUserTransactionWarning, because EF Core now takes a database lock so two instances can’t migrate at the same time. Just call it directly:
await db.Database.MigrateAsync(cancellationToken);
For production, consider not migrating on application startup at all. Generate an idempotent script (dotnet ef migrations script --idempotent) or a migration bundle (dotnet ef migrations bundle) and run it as a deliberate step in your release pipeline, where it can be reviewed and approved like any other change.
5. Smaller changes worth knowing
- Orphans aren’t deleted automatically (EF Core 7). Removing the link between a parent and an optional child no longer deletes the child. If your code relied on that, delete the child explicitly.
- Scaffolding produces different types (EF Core 8). If you’re database-first and re-scaffold,
datecolumns becomeDateOnlyandtimecolumnsTimeOnly, and non-nullableboolcolumns with a default are no longerbool?. Expect a noisy diff. - Enums inside JSON columns are stored as numbers (EF Core 8) rather than strings. Add
HasConversion<string>()to keep strings. - JSON columns use SQL Server’s
jsontype (EF Core 10) on Azure SQL or compatibility level 170. Existingnvarchar(max)columns are altered on upgrade withUseAzureSql; keep them withHasColumnType("nvarchar(max)")if you need to. ExecuteUpdateAsynctakes a normal lambda (EF Core 10), not an expression tree. Code that built the setters as anExpressionneeds rewriting, though it gets simpler.- Tool versions must match. Update the
dotnet-eftool andMicrosoft.EntityFrameworkCore.Designto the same major version as EF Core. Mismatched tools give confusing errors.
An upgrade checklist
- Upgrade in one pass to .NET 10 / EF Core 10, but read the breaking-change notes for EF Core 7, 8, 9 and 10.
- Inventory your SQL Servers: version, compatibility level, and whether each has a certificate your app servers trust.
- Fix certificates before the upgrade lands. Plan
TrustServerCertificate=Trueonly for local development, and treat any use of it in a higher environment as a temporary, tracked exception. - List tables with triggers and add
UseSqlOutputClause(false)for each. - Run the migrations against a copy of each database in Test and PreProd, and fix any
PendingModelChangesWarningproperly. - Turn on EF Core’s SQL logging in Test (
Microsoft.EntityFrameworkCore.Database.Command) and compare the generated SQL for your most important queries. - Load-test PreProd with production-like data volumes before go-live, because query-plan changes are where the surprises hide.