Jamie R Rytlewski
105 posts

Jamie R Rytlewski
@jamierytlewski
Senior App Dev




Fact: Most .NET developers write EF Core queries that negatively impact database costs. Here are the TOP 5 EF Core mistakes killing your API performance right now: 1. No projections You return full entities when the client needs 3 fields. Fix: Use .Select(x => new { x.Id, x.Name, x.Status }) Result: Less data transferred, faster serialization, smaller SQL query. 2. N+1 queries You load orders, then loop and query each customer separately. Fix: Use .Include(o => o.Customer) or a projection that flattens the data. Result: 1 SQL query instead of 51. 3. Tracking read-only data EF Core tracks every entity by default. Change tracking costs memory and CPU. Fix: Add .AsNoTracking() to every read-only query. Result: 30-40% faster on large result sets. 4. Late filtering Calling .ToListAsync() before .Where() loads everything into memory first. Fix: Always filter, sort, and page BEFORE materializing. Result: SQL Server does the work instead of your app server. 5. SingleOrDefault vs FirstOrDefault SingleOrDefault scans the entire result set to guarantee uniqueness. Fix: Use FirstOrDefaultAsync when you just need the first match. Result: Faster queries, especially on large tables. None of these are hard to fix. All of them make a measurable difference. Check your codebase today. I guarantee at least 2 of these are hiding in there. Found this useful? Repost to your network. For more .NET tips, join my free newsletter: newsletter.codewithmukesh.com
















TRMNL plugins are leaving me no time for anything else 😅









