You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Query precompiler folds conditionals on captured variables using fake defaults and drops a SQL branch #39428
When the query precompiler generates a query, it evaluates captured variables using fake default values and lets the funcletizer simplify the tree. A conditional whose test depends only on captured values is evaluated at generation time, and one arm is dropped. The generated SQL hard-codes the arm the default value picked, so the variable's runtime value is ignored.
Actual (precompiled): only the active rows; the SQL filters on IsActive whatever all is
includeInactive ? true : e.IsActive behaves the same way.
Analysis
src/EFCore.Design/Query/Internal/CSharpToLinqTranslator.cs:449-460,1314-1321: captured fields get fake defaults (false, 0, null) during generation.
src/EFCore/Query/Internal/ExpressionTreeFuncletizer.cs:510-522: the conditional's test is evaluated and one arm discarded. :366-409 and :416-445 do the same for && / ||, and :376-394 for ??.
Not affected: a captured bool passed as an ordinary method argument (parameterized by the funcletizer, :1024-1030,1063-1122).
Workaround
Rewrite the guard so the conditional's test depends on the row, e.g. e.IsActive ? true : all instead of all || e.IsActive, or choose a nullable key outside the expression tree. EF.Parameter(...) keeps the SQL arm but then fails in the generated extractor.
+1 from an app preparing to ship EF Core 10 NativeAOT on iOS. These bugs give different results from the same LINQ under the JIT with no error, so a precompiled build cannot be trusted without checking every query.
We have the reported shape in shared server/mobile code, for example an ownership check
where anyOwnedResource is a captured bool. With the fake default (false), the bug described here would keep only the Contains arm in the generated SQL, so when anyOwnedResource is true at run time the query would return fewer rows than under the JIT. Today this query fails to precompile for an unrelated reason (captured collection Contains), so fixing that would expose it to this bug.
Please consider servicing the fix into 10.0.x together with #37323: both are correctness bugs in a feature 10.0 documents.
Activity
davidortinau commentedon Nov 5, 2026
+1 from an app preparing to ship EF Core 10 NativeAOT on iOS. These bugs give different results from the same LINQ under the JIT with no error, so a precompiled build cannot be trusted without checking every query.
We have the reported shape in shared server/mobile code, for example an ownership check
where
anyOwnedResourceis a capturedbool. With the fake default (false), the bug described here would keep only theContainsarm in the generated SQL, so whenanyOwnedResourceis true at run time the query would return fewer rows than under the JIT. Today this query fails to precompile for an unrelated reason (captured collectionContains), so fixing that would expose it to this bug.Please consider servicing the fix into 10.0.x together with #37323: both are correctness bugs in a feature 10.0 documents.
Preserve captured-dependent branches during query precompilation (dot…