Menu

Post image 1
Post image 2
1 / 2
0

EF Core, LINQ & Dapper in .NET — Make Your Data Layer 4 Faster (Real Benchmarks)

DEV Community: csharp·kirandeepjassal-crypto·3 days ago
#JaGdvSjv
#dev#dapper#core#fullscreen#photo#article
Reading 0:00
15s threshold

Data access is where most .NET apps win or lose their performance budget. EF Core isn't slow — three default behaviours are. I took a 1,000-row product list endpoint and pulled it down from 38 ms to 8 ms using real production benchmarks, one perf lever at a time. The benchmark ladder Approach Mean Allocated Tracked entity (default) 38.2 ms 4.1 MB AsNoTracking() 24.7 ms 1.8 MB Projection to DTO 12.1 ms 0.6 MB EF.CompileAsyncQuery 9.8 ms 0.4 MB Dapper hand-tuned SQL 8.4 ms 0.3 MB Raw SqlDataReader 7.9 ms 0.2 MB The single biggest win — projection Stop returning entities. Project to DTOs that contain only the columns your endpoint actually uses. public record ProductListDto ( Guid Id , string Name , decimal Price , string CategoryName , int ReviewCount ); var products = await db . Products . Select ( p => new ProductListDto ( p . Id , p . Name , p . Price , p . Category . Name , p . Reviews . Count ())) .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More