EF Core 11 Part II: Faster Queries and SQL Server Upgrades


Barret Blake, Architect
This is part 2 of a 2-part post covering all the new stuff in Entity Framework Core 11
In Part I, we looked at the migration improvements in EF Core 11 and how they make life easier for teams. In this part, we’re turning to the stuff that happens at query time.
There are two big buckets here. The first is performance improvements you get just by upgrading. EF Core 11 generates leaner SQL for a lot of common query shapes, which means some of your existing queries are going to get faster without you changing a line of code. The second is a long list of SQL Server-specific features, including vector search, hybrid search, full-text search setup through migrations, and some nice quality-of-life changes for temporal tables.
We’ll wrap up with a quick roundup of the smaller changes for other providers.
Performance You Get for Free
Leaner SQL for Reference Navigations
Almost every application does this: including a reference (to-one) navigation alongside a collection.
var blogs = await context.Blogs
.Include(b => b.BlogType)
.Include(b => b.Posts)
.AsSplitQuery()
.ToListAsync();
With split queries, EF runs one query for the blogs and a separate query for the posts. Before EF Core 11, that posts query included a join to BlogType that it didn’t actually need:
-- Before EF Core 11
SELECT [p].[Id], [p].[BlogId], [p].[Title], [b].[Id], [b0].[Id]
FROM [Blogs] AS [b]
INNER JOIN [BlogType] AS [b0] ON [b].[BlogTypeId] = [b0].[Id]
INNER JOIN [Post] AS [p] ON [b].[Id] = [p].[BlogId]
ORDER BY [b].[Id], [b0].[Id]
EF Core 11 prunes it:
-- EF Core 11
SELECT [p].[Id], [p].[BlogId], [p].[Title], [b].[Id]
FROM [Blogs] AS [b]
INNER JOIN [Post] AS [p] ON [b].[Id] = [p].[BlogId]
ORDER BY [b].[Id]
Single queries get a related improvement. EF used to add the keys of included reference navigations to the ORDER BY clause, even though the parent’s key already uniquely identifies the row. Those redundant columns are gone now, too.
How much does it matter? In the EF team’s benchmarks, a simple split query scenario got 29% faster, and a single query scenario got 22% faster. The more reference navigations you include, the more you stand to gain. As always, your results will depend on your schema and your data, but you’re pretty much guaranteed to get at least some performance improvement regardless.
No More Pointless CASTs
Sometimes EF generated a SQL CAST that converted a column to the type it already was:
SELECT [u].[Id], [u].[Name]
FROM [Users] AS [u]
WHERE CAST([u].[Name] AS nvarchar(max)) LIKE N'Name%'
That CAST doesn’t change the result, but it’s not harmless. Wrapping a column in a function can stop the database from using an index on that column, which can turn an index seek into a full scan. EF Core 11 detects these no-op casts and strips them out:
SELECT [u].[Id], [u].[Name]
FROM [Users] AS [u]
WHERE [u].[Name] LIKE N'Name%'
This showed up most often with value-converted properties, where the .NET type has an implicit conversion to the database type. If you use value conversions for strongly typed IDs or value objects, which plenty of DDD-minded teams do, this one is worth paying attention to. Some queries that weren’t using your indexes may start using them after the upgrade.
Better GroupBy
GroupBy has historically been one of the rougher edges of EF’s LINQ translation. EF Core 11 continues to smooth it out. Aggregates over reference navigations are now translated using joins before grouping instead of correlated subqueries. You can compose navigations and joins over a per-group top result. And projecting into anonymous types or DTOs through left joins and grouping now materializes correctly.
If you’ve ever rewritten a GroupBy query by hand because EF’s translation was slow or simply failed, it’s worth trying the LINQ version again on EF Core 11.
New LINQ Operators: FullJoin, MaxBy, and MinBy
.NET 11 adds a FullJoin operator to LINQ, and EF Core 11 translates it to a SQL FULL JOIN. It keeps rows from both sides, matching them where the keys line up:
var results = await context.Customers
.FullJoin(
context.Orders,
c => c.Id,
o => o.CustomerId,
(c, o) => new { Customer = c, Order = o })
.ToListAsync();
SELECT [c].[Id], [c].[Name], [o].[Id], [o].[CustomerId], [o].[OrderDate]
FROM [Customers] AS [c]
FULL JOIN [Orders] AS [o] ON [c].[Id] = [o].[CustomerId]
EF Core 11 also translates MaxBy and MinBy, along with their async versions. The difference from Max and Min is that they return the element with the highest or lowest value, not the value itself:
var blogWithMostPosts = await context.Blogs.MaxByAsync(b => b.Posts.Count());
SELECT TOP(1) [b].[Id], [b].[Name]
FROM [Blogs] AS [b]
ORDER BY (
SELECT COUNT(*)
FROM [Posts] AS [p]
WHERE [b].[Id] = [p].[BlogId]) DESC
Before, you’d have written OrderByDescending(...).FirstOrDefaultAsync() to get the same result. MaxByAsync says what you mean.
See It for Yourself
The easiest way to see these changes in your own code is to call ToQueryString() on a query before and after upgrading:
var sql = context.Blogs
.Include(b => b.BlogType)
.Include(b => b.Posts)
.AsSplitQuery()
.ToQueryString();
Or turn on EF’s SQL logging and compare. If you’ve got a handful of known heavy queries, it’s worth benchmarking them before and after the upgrade. Not only will you know what you gained, you’ll catch any regressions early.
SQL Server
First, a Heads-Up: The Default Compatibility Level Changed
Before we get into the new features, there’s one change SQL Server users need to know about. UseSqlServer now defaults to compatibility level 160, which is SQL Server 2022. That lets EF use newer SQL by default, such as the LEAST and GREATEST functions.
If you’re running against an older version of SQL Server, or a database set to an older compatibility level, you need to tell EF explicitly. Otherwise EF may generate SQL your database can’t run:
options.UseSqlServer(connectionString, o => o.UseCompatibilityLevel(150));
The same switch works in the other direction. Several of the features below require SQL Server 2025, which is compatibility level 170, and you’ll need to opt in to get them.
Vector Search with Approximate Indexes
EF Core 10 added EF.Functions.VectorDistance() for vector similarity search. That works, but it calculates the exact distance against every row, which gets slow as your data grows.
SQL Server 2025 adds vector indexes, which support approximate nearest-neighbor (ANN) search. You trade a little precision for a lot of speed, and for most semantic search and retrieval-augmented generation (RAG) scenarios, that’s exactly the trade you want. EF Core 11 lets you create the index through migrations:
modelBuilder.Entity<Article>()
.HasVectorIndex(a => a.Embedding, "cosine");
And query it with the new VectorSearch() method:
var articles = await context.Articles
.VectorSearch(a => a.Embedding, queryEmbedding, "cosine")
.OrderBy(r => r.Distance)
.Take(5)
.WithApproximate()
.ToListAsync();
Take() sets how many results you want, and WithApproximate() tells SQL Server to use the vector index. Leave off WithApproximate(), and you get an exact search instead. Each result is a VectorSearchResult<TEntity>, so you have access to the distance alongside the entity.
One important caveat: VECTOR_SEARCH() and vector indexes are still experimental in SQL Server, and the EF Core APIs for them may change. Great for exploring and prototyping, but plan on some churn before you build anything critical on top of it.
The appeal here is hard to overstate. If your application already runs on SQL Server, your RAG store can live in the same database as the rest of your data, queried with the same EF Core you already use.
Vectors Are No Longer Loaded by Default
Here’s a change that will speed things up for anyone storing embeddings, but it could also break some code, so pay attention.
Embeddings are big, often hundreds or thousands of floating-point numbers per row. Most of the time you store them and search with them, but you rarely need to read them back. So in EF Core 11, SqlVector<T> properties are no longer included when EF loads an entity:
// The Embedding column is not included in the SELECT
var articles = await context.Articles.OrderBy(a => a.Title).ToListAsync();
The payoff is significant. In the EF team’s benchmark, loading entities was almost 9x faster against a local database and around 22x faster against a remote Azure SQL database, because there’s so much less data going over the wire.
The catch: if you have code that loads an entity and then reads its vector property, that property won’t be populated anymore. If you need the vector, project it explicitly:
var embeddings = await context.Articles
.Select(a => new { a.Id, a.Embedding })
.ToListAsync();
Vector properties still work normally in Where and OrderBy clauses, and with VectorDistance() and VectorSearch(). They’re just left out of the entity itself. Search your codebase for any place that reads an embedding off a loaded entity before you upgrade.
Full-Text Search, Set Up Through Migrations
SQL Server’s full-text search has always required some setup: a full-text catalog, plus a full-text index on the columns you want to search. EF Core has supported querying with EF.Functions.FreeText() and EF.Functions.Contains() for a long time, but the setup itself meant hand-written SQL in your migrations.
EF Core 11 lets you configure it in your model:
modelBuilder.HasFullTextCatalog("ftCatalog");
modelBuilder.Entity<Article>()
.HasFullTextIndex(a => a.Body)
.UseKeyIndex("PK_Articles")
.UseCatalog("ftCatalog");
Migrations take care of the rest:
CREATE FULLTEXT CATALOG [ftCatalog];
CREATE FULLTEXT INDEX ON [Articles]([Body]) KEY INDEX [PK_Articles] ON [ftCatalog];
EF Core 11 also supports SQL Server’s FREETEXTTABLE() and CONTAINSTABLE() functions. Unlike the predicate versions, these return a relevance rank with each result, so you can sort by how well each row matches:
var results = await context.Articles
.FreeTextTable("database performance", a => a.Body)
.Select(r => new { Article = r.Value, r.Rank })
.OrderByDescending(r => r.Rank)
.ToListAsync();
Hybrid Search
Here’s where the pieces come together. Full-text search is great at finding exact words and phrases. Vector search is great at finding things that mean the same thing, even when they use different words. Hybrid search runs both and merges the results, so you get the best of each.
EF Core 11 has all the building blocks: FreeTextTable() for the full-text side, VectorSearch() for the semantic side, and the new FullJoin to combine them so that a strong match from either side makes it into the results. The rankings are then merged using a technique called reciprocal rank fusion:
var results = await context.Articles
.FreeTextTable<Article, int>(textualQuery, topN: k)
.Join(
context.Articles,
fts => fts.Key,
a => a.Id,
(fts, a) => new { Article = a, fts.Rank })
.FullJoin(
context.Articles.VectorSearch(a => a.Embedding, queryEmbedding, "cosine")
.OrderBy(r => r.Distance)
.Take(k)
.WithApproximate(),
fts => fts.Article.Id,
vs => vs.Value.Id,
(fts, vs) => new
{
Article = fts != null ? fts.Article : vs.Value,
FullTextRank = fts == null ? null : (int?)fts.Rank,
VectorDistance = vs == null ? null : (double?)vs.Distance
})
.Select(x => new
{
x.Article,
RrfScore = (x.FullTextRank == null ? 0.0 : 1.0 / (k + x.FullTextRank.Value))
+ (x.VectorDistance == null ? 0.0 : 1.0 / (k + x.VectorDistance.Value))
})
.OrderByDescending(x => x.RrfScore)
.Take(10)
.Select(x => x.Article)
.ToListAsync();
It probably makes more sense hidden away in a repository or a specification rather than left inline, but the fact that it’s all expressible in LINQ, and runs as a single query against your existing database, makes it a big deal for anyone building search or RAG features on SQL Server.
Faster Contains on JSON Collections
If you store primitive collections as JSON, such as a list of tags, a Contains query used to translate to an OPENJSON subquery. On SQL Server 2025, EF Core 11 can use the new JSON_CONTAINS function instead:
var articles = await context.Articles
.Where(a => a.Tags.Contains("ef-core"))
.ToListAsync();
SELECT [a].[Id], [a].[Title], [a].[Tags]
FROM [Articles] AS [a]
WHERE JSON_CONTAINS([a].[Tags], 'ef-core') = 1
It’s simpler SQL, and JSON_CONTAINS can take advantage of a JSON index, giving you a performance boost. But you have to opt in by using a SQL Server version of 2025 and setting the compatibility level to 170:
options.UseSqlServer(connectionString, o => o.UseCompatibilityLevel(170));
One limitation: JSON_CONTAINS can’t search for null values. If EF can’t be sure that either the value you’re searching for or the collection’s elements are non-nullable, it falls back to the old OPENJSON translation. If you need more control, such as searching at a specific JSON path, there’s also a new EF.Functions.JsonContains() you can call directly.
EF Core 11 can also now create SQL Server JSON indexes on paths inside complex types mapped to JSON columns. If you’re working with complex types and JSON columns, Sadukie’s post on querying deeply nested game state is a great deep dive.
Temporal Tables: Period Columns as Real Properties
If you use SQL Server temporal tables, you know the period columns, PeriodStart and PeriodEnd, had to be shadow properties. They existed in the EF model but not on your entity class, so getting at them meant EF.Property<DateTime>(e, "PeriodStart") sprinkled through your queries.
In EF Core 11, you can map them to regular properties:
public class Employee
{
public Guid EmployeeId { get; set; }
public string Name { get; set; } = string.Empty;
public string Position { get; set; } = string.Empty;
public DateTime PeriodStart { get; set; }
public DateTime PeriodEnd { get; set; }
}
modelBuilder.Entity<Employee>()
.ToTable("Employees", b => b.IsTemporal(t =>
{
t.HasPeriodStart(e => e.PeriodStart);
t.HasPeriodEnd(e => e.PeriodEnd);
}));
And then use them like any other property:
var history = await context.Employees
.TemporalAll()
.Where(e => e.EmployeeId == employeeId)
.OrderBy(e => e.PeriodStart)
.Select(e => new { e.Position, e.PeriodStart, e.PeriodEnd })
.ToListAsync();
SQL Server still generates the values. EF leaves them out of inserts and updates, just as before. It’s a small change, but it makes audit and history queries a lot more readable.
More Date and Time Translations
A few more date and time operations now translate to SQL instead of forcing you to pull data into memory:
DateTimeOffsetpropertiesDateTime,UtcDateTime, andLocalDateTime, along withOffset.TotalMinutesToOffset(), which translates toSWITCHOFFSET- Creating a
DateTimeOffsetfrom aDateTimewithnew DateTimeOffset(dateTime)ornew DateTimeOffset(dateTime, offset), which translates toTODATETIMEOFFSET - A new
EF.Functions.DateTrunc()for truncating dates and times to a given precision, such as the day or hour, which translates toDATETRUNC
DateTrunc() in particular is handy for reporting queries, like grouping orders by day or by hour.
The Smaller Stuff
A few more items worth a quick mention:
EF.Functions.JsonPathExists()checks whether a path exists in a JSON document. On SQL Server, it translates toJSON_PATH_EXISTS, which requires SQL Server 2022 or later.- SQLite now supports ordering inside
string.Joinandstring.Concataggregations, which translates togroup_concatwithORDER BYand requires SQLite 3.44 or later.Microsoft.Data.Sqlitecan also bindUInt128parameter values. - Cosmos DB gets a big update, including complex types, indexing policy configuration, transactional batches, bulk execution, and a switch from Newtonsoft.Json to System.Text.Json. That last one comes with some breaking changes, so Cosmos users should read the breaking changes carefully before upgrading.
- Complex types can now be used with table-per-type and table-per-concrete-type inheritance, among other improvements. Sadukie’s post covers complex types in depth.
Wrapping Up
Between the two parts of this series, EF Core 11 has something for just about every team. Part I covered the day-to-day workflow improvements around migrations. This part covered what happens when your queries run: leaner SQL that makes existing queries faster for free, and a substantial set of SQL Server features that make it a much more capable home for search and AI workloads.
If you do one thing after upgrading, run your heaviest queries through ToQueryString() or a benchmark and see what changed. And if you’re on SQL Server, check your compatibility level before you deploy.