Performance Improvement
Improved API performance by identifying and fixing inefficient LINQ-to-Entity query patterns.
Impact
10x faster responses
Performance
A set of API endpoints in an internal application were timing out under normal load. Requests that should complete in under a second were taking 8–15 seconds. This impacted the user-facing features built on top of them.
Using SQL Server Profiler and EF Core query logging, I traced the slowdowns to a classic N+1 query pattern — LINQ queries that appeared fine in code were generating hundreds of individual SQL round-trips per request.
The specific issues:
.Include() calls forcing repeated database hits for related data.ToList() calls pulling entire tables into memory before filtering in C#.Include() and .ThenInclude() chains.Where() before .ToList()) so SQL Server handles itResponse times dropped from 8–15 seconds to under 1 second — roughly a 10x improvement. The fix required no schema changes and no infrastructure changes.