EF Core's query cache key includes constants in the expression tree, so queries built with Expression.Constant(userValue), string-built dynamic LINQ, or EF.Constant on varying values create a new cache entry and a new translation for every value. The impact: CPU spent translating on every request instead of once, memory growing with cached entries (until the cache's size limit evicts them, causing more re-translation), and on SQL Server a matching flood of single-use plans in the plan cache. Fix it by capturing values in closures (they become SQL parameters), building dynamic predicates with parameter expressions, avoiding EF.Constant for high-cardinality values, and confirming with the query cache hit rate in dotnet-counters monitor Microsoft.EntityFrameworkCore.
Checks they know constants in expression trees create a cache entry per value
Last updated 23 Nov 2026.