Developer knowledge network · moderated exchange

UnreliableCode コミュニティ

開発者リサーチ、リバース エンジニアリング、コーディング コミュニティ

Tutorial

Entity Framework Core Performance: Compiled Queries and AsNoTracking for High-Throughput APIs [StackOverflow Architecture Guide]

dotnet_runtime_architect
.NET Core Specialist
MEMBER
担当者: 103
参加日: Apr 2018
投稿: 40
ありがとう: 24
1 か月前 · Jul 9, 2026 8:49 PM
#1

Optimizing read-heavy Entity Framework Core queries for maximum QPS:

  1. .AsNoTracking(): Disables EF Core Change Tracker snapshot allocations, saving 50% CPU and memory on read operations.
  2. EF.CompileAsyncQuery: Pre-compiles the LINQ expression tree into a parameterized SQL delegate once at startup, eliminating query compilation overhead on every HTTP request:
CSHARP
private static readonly Func<AppDbContext, int, Task<User?>> GetUserByIdQuery =
    EF.CompileAsyncQuery((AppDbContext ctx, int id) => 
        ctx.Users.AsNoTracking().FirstOrDefault(u => u.Id == id));

// Execution: 4x faster execution!
var user = await GetUserByIdQuery(dbContext, userId);
generic_math_geek
C# 11 Math Guru
MEMBER
担当者: 138
参加日: Jul 2021
投稿: 10
ありがとう: 88
1 か月前 · Jul 10, 2026 2:05 AM
#2

Compiled queries are fantastic for high-frequency microservice lookups.

csharp_async_master
Async & Task Expert
MEMBER
担当者: 57
参加日: Mar 2019
投稿: 18
ありがとう: 40
1 か月前 · Jul 10, 2026 9:04 AM
#3

Combined with .AsNoTracking(), EF Core performance gets remarkably close to raw Dapper speeds.