Tutorials Entity Framework Core Tutorial
Projection with LINQ in EF Core
Projection with LINQ 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 35 of 100
Projection with LINQ in EF Core
Beginner ✓ → Intermediate → Advanced → Professional
Intermediate · 2 — Data & queries · ~6 min · Module 4: LINQ
What is this?
Projection selects specific columns or shapes with Select into anonymous types, records, or DTOs — EF generates SQL that returns only needed columns.
Why should you care?
ShopNest product cards need Id, Name, Price, ThumbnailUrl — not full description blobs or internal cost fields.
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 cards = await _context.Products
.Where(p => p.IsPublished)
.Select(p => new ProductCardDto
{
Id = p.Id,
Name = p.Name,
Price = p.Price,
CategoryName = p.Category!.Name
})
.ToListAsync();
What happened?
- Select with DTO maps to SQL SELECT listing only projected columns plus JOIN to Category for Name — no full Product entity materialized.
Practice next
- Replace ToList of entities with Select to DTO.
- Compare network payload size before and after.
- Project nested collections carefully — can cause cartesian explosion.
- Add computed DiscountPrice = p.Price * 0.9m inside Select.
- Project to record type instead of class for immutable API models.
Remember
Select projects columns and shapes in SQL. DTO projection reduces data transfer. Avoid loading entities when DTO suffices.
ShopNest mobile listing
Mobile API projects ProductCardDto with category name in one JOIN query.
Outcome: 70% smaller JSON responses on 4G networks during browse.
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!