SQL Server Interview Question #286
What is projection and why is it important for EF Core performance?
ASP.NET Core, EF Core & SQL Server Real-World Scenarios Senior Advanced
Detailed Explanation
Projection means selecting only the fields required by the operation instead of loading complete entities.
For example, a product-list page may need Id, Name, Price, and ImageUrl rather than every product column and navigation property. Projection reduces transferred data, materialization work, memory usage, and often improves SQL efficiency.
DTO and ViewModel projections are particularly useful in ASP.NET Core applications.
Code Example
var products = await db.Products
.AsNoTracking()
.Where(p => p.IsActive)
.Select(p => new ProductListVm
{
Id = p.Id,
Name = p.Name,
Price = p.Price
})
.ToListAsync();