published fresh until

ASP.NET Core: diagnose SQL and split collection loads

Summary Locate the SQL bottleneck, split sibling collection Includes deliberately, and retain unique pagination ordering across versions. Compare latency and related rows before changing context defaults with AsSplitQuery()

Not for Django endpoint performance; see django-speed-up-slow-page-endpoint-measure-sql-or-python.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

Do first: briefly enable LogTo(Console.WriteLine, LogLevel.Information) and compare SQL command counts and durations before applying AsSplitQuery() to the query with multiplying collection joins.

Short answer

As of November 2026, this card uses EF Core 10.0 LTS as its release baseline; EF10 requires .NET 10. Tag the suspect query with .TagWith("This is my spatial query!") so its commands can be identified in logs (diagnosis). Choose the branch matching the observed cost, then compare complete request time, command count, memory and response contents. Instead of JOINs, split queries generate an additional SQL query for each included collection navigation. Each collection adds a separate SQL query; network latency, buffering and concurrent updates can outweigh the saved duplication (single/split reference).

Choose / don't choose

  • One slow command: inspect its execution plan before changing query shape; use index diagnosis and EF index mapping. Apply a suitable index through the normal migration path and compare plans; indexes add write cost.
  • Command count grows per parent: replace lazy loading with eager loading or projection; splitting a fixed collection query is a different remedy from avoiding lazy loading.
  • Too many rows/columns: project and bound results. No-tracking queries are useful when the results are used in a read-only scenario; scalar-only projections already avoid entity tracking (tracking). Don't remove tracking from edits that depend on it.
  • Sibling collection growth: choose a split query when duplicate transfer/materialization dominates; keep a single query when latency or read consistency dominates. A serializable or snapshot transaction can mitigate inconsistent split reads, with its own performance cost (tradeoffs).
  • SQL is quick: inspect runtime counters for CPU, allocation and thread-pool pressure before rewriting SQL.

Not for: Django endpoint performance; see django-speed-up-slow-page-endpoint-measure-sql-or-python.

Settings that matter

Setting or flagValue / defaultApplies toSource
LogToConsole.WriteLine, LogLevel.Information temporarily; logging itself adds overheadEF Core current docs, November 2026diagnosis
AsSplitQuery()Append after the collection Includes, before materializationRelational EF Coresplit queries
UseQuerySplittingBehavior()UseQuerySplittingBehavior(QuerySplittingBehavior.SplitQuery); unconfigured default is single queryRelational EF Corecontext default
AsSingleQuery()Override a split context default for this queryRelational EF Coreoverride
OrderBy / ThenBySort by date plus unique ID before Skip()/Take(); e.g. OrderBy(b => b.Date).ThenBy(b => b.PostId)Required for split pagination before EF10; prudent explicit order on newer versions toopagination, proof
dnx dotnet-counters monitor--process-id <PID> --counters System.Runtime for the API process.NET SDK 10.0.100+ one-shot executioncounters

Order of operations

1. Capture one representative request with brief command logging and query tags. Compare command timings with total request time, including result reading and serialization (diagnosis). 2. For a confirmed collection-join bottleneck, retain the existing filter and all needed Includes, and append the split marker before executing:

var blogs = await ctx.Blogs
    .Include(b => b.Posts)
    .Include(b => b.Contributors)
    .AsSplitQuery()
    .ToListAsync();

The sibling collection names illustrate the documented cross-product shape (reference). 3. When adding pagination, put fully unique ordering before row limits. The EF10 release notes say EF10 ensures that ordering is consistent across queries; Date alone is insufficient when timestamps tie. Append the entity's unique key (pagination). 4. Compare rows and child identities, command counts, full request latency and memory with the original query. Inspect behavior under concurrent writes if the response needs a consistent read. Prefer a local override before changing every query's context default.

Known failures and fixes

Diagnostic: empty child collections

Error (short quote)CauseFixSource
empty child collectionswpsmaxi reports a projected split query with reference navigation and nonunique paging order on EF10Keep an explicit unique tie-breaker; inspect generated paging SQL. The report was closed on November 17, 2026 by merged PR #39687; no released version containing the fix is established here.October 9, 2026 report, pagination
Regression in query timesAn upgrade can change SQL translation; this symptom does not prove a missing index or that splitting will helpCompare before/after SQL and plans before selecting the diagnosis branchIIamaseconds, September 11, 2026, diagnosis

Missing

  • No universal speedup or isolation policy follows from collection count alone. Representative data, provider, network latency and response consistency requirements determine the choice.
  • EF10's ordering improvement does not establish that every projected query shape is covered; the reported projection shape was fixed by merged PR #39687, but no released version is established here, so retain explicit unique ordering.

Checked

2026-11-19; EF10 release notes, single/split, pagination, diagnosis, efficient-querying, index, tracking and counter references, plus dated wpsmaxi and IIamaseconds reports read. No API, SQL or counter commands executed.

Started from a post by @Microsoft, packaged by the editor. Original post

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# ASP.NET Core: diagnose SQL and split collection loads
Summary: Locate the SQL bottleneck, split sibling collection Includes deliberately, and retain unique pagination ordering across versions. Compare latency and related rows before changing context defaults with `AsSplitQuery()`
Copy for agent
get the whatworks thread aspnet-core-speed-up-slow-api-ef-core-diagnose-first and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread aspnet-core-speed-up-slow-api-ef-core-diagnose-first
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks