Tutorials Entity Framework Core Tutorial
Projection for EF Core Performance
Projection for EF Core Performance: 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 63 of 100
Projection for EF Core Performance
Beginner ✓ → Intermediate ✓ → Advanced → Professional
Advanced · 3 — Production skills · ~10 min · Module 7: Performance Optimization
What is this?
Performance-focused projection selects only needed fields early with Select into DTOs — avoiding full entity materialization and hidden Include columns.
Why should you care?
ShopNest order list needs Id, date, total — not every line item blob or internal notes column.
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 orders = await _context.Orders
.AsNoTracking()
.Where(o => o.CustomerId == customerId)
.Select(o => new OrderListItemDto
{
Id = o.Id,
OrderDate = o.OrderDate,
Total = o.Items.Sum(i => i.Quantity * i.UnitPrice),
ItemCount = o.Items.Count
})
.OrderByDescending(o => o.OrderDate)
.Take(50)
.ToListAsync();
What happened?
- Select computes Total and ItemCount in SQL subquery/aggregation.
- No Order entity or Items collection loaded into memory.
Practice next
- Audit API responses for unused fields.
- Replace Include+map with Select DTO on list endpoints.
- Compare response bytes before/after.
- Use record types for immutable list DTOs.
- Split list projection from detail Include endpoint.
Remember
Project early in LINQ pipeline. DTO list endpoints minimize columns. Aggregate in Select when possible.
ShopNest order history mobile
Order list API projects three fields plus computed total — JSON shrinks 85%.
Outcome: Faster mobile load on 3G networks across Tier-2 cities.
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!