Tutorials Entity Framework Core Tutorial
Query Splitting in EF Core
Query Splitting in EF Core: free step-by-step lesson with examples, common mistakes, and interview tips — part of Entity Framework Core Tutorial on Toolliyo Academy.
On this page
Entity Framework Core Tutorial · Lesson 57 of 100
Query Splitting in EF Core
Beginner ✓ → Intermediate ✓ → Advanced → Professional
Advanced · 3 — Production skills · ~10 min · Module 6: Advanced EF Core
What is this?
Query splitting breaks one SQL command with cartesian JOIN into multiple SELECTs — AsSplitQuery on Include queries with multiple collections.
Why should you care?
ShopNest order detail Include Items and Payments — single JOIN duplicates order columns explosively; split query keeps rows lean.
See it live — copy this example
Paste into a .NET project with EF Core packages, then run with LocalDB/SQL Server (dotnet ef / dotnet run).
var order = await _context.Orders
.AsSplitQuery()
.Include(o => o.Items)
.Include(o => o.Payments)
.Include(o => o.Customer)
.FirstOrDefaultAsync(o => o.Id == orderId);
What happened?
- AsSplitQuery issues separate SQL per Include collection instead of one wide JOIN.
- Reduces duplicated scalar columns and memory.
Practice next
- Enable split on queries including two or more collections.
- Compare row counts in SQL Profiler single vs split.
- Set UseQuerySplittingBehavior.SplitQuery as default if most queries Include collections.
- Toggle AsSingleQuery() on same Include and compare payload size.
- Configure split as default in UseSqlServer options.
Remember
AsSplitQuery avoids cartesian explosion. Use with multiple collection Includes. Trade one round trip for row duplication savings.
ShopNest order detail
Order admin view Includes Items + Payments with AsSplitQuery.
Outcome: SQL rows drop from 500 duplicated to 50 lean rows for 10-item order.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!