Entity Framework Core Interview Question #127

Why can loading too much data hurt EF Core performance?

Performance, Raw SQL, Stored Procedures & Advanced Queries Senior Advanced

Quick Interview Answer

Unnecessary rows and columns increase database work, network traffic, materialization, memory use, garbage collection, and possibly change-tracking overhead. Apply filtering and projection before materialization and paginate large collections rather than loading everything into application memory.

Detailed Explanation

Unnecessary rows and columns increase database work, network traffic, materialization, memory use, garbage collection, and possibly change-tracking overhead. Apply filtering and projection before materialization and paginate large collections rather than loading everything into application memory.

Code Example

var names = await db.Products
    .Where(p => p.IsPublished)
    .Select(p => p.Name)
    .Take(100)
    .ToListAsync();