← Back to DAGDA | Support | Source: https://github.com/dotnet/efcore/pull/39847
Skip to content

Don't rewrite Any/All to Contains when the item references the lambda parameter - #39847

Open
bkoelman wants to merge 1 commit into
dotnet:mainfrom
bkoelman:fix/39351-any-contains-lambda-parameter
Open

bkoelman wants to merge 1 commit into
dotnet:mainfrom
bkoelman:fix/39351-any-contains-lambda-parameter

Conversation

@bkoelman

Copy link
Copy Markdown
Contributor

Don't rewrite Any/All to Contains when the item references the lambda parameter

  • Skip the Any(i => i == foo) to Contains(foo) and All(i => i != foo) to !Contains(foo) normalization in QueryOptimizingExpressionVisitor when foo references i, since foo would otherwise be moved out of the lambda
  • Such queries now go through the regular Any/All translation (EXISTS / NOT EXISTS)
  • Add tests with SQL baselines for SQLite, SQL Server (including JSON type and old compatibility level) and Cosmos

Fixes #39351, supersedes #39433

  • I've read the guidelines for contributing and seen the walkthrough
  • I've posted a comment on an issue with a detailed description of how I am planning to contribute and got approval from a member of the team
  • The code builds and tests pass locally (also verified by our automated build checks)
  • Commit messages follow this format:
        Summary of the changes
        - Detail 1
        - Detail 2

        Fixes #bugnumber
  • Tests for the changes have been added (for bug fixes / features)
  • Code follows the same patterns and style as existing code in this repo

…lambda parameter

- Skip the `Any(i => i == foo)` to `Contains(foo)` and `All(i => i != foo)` to `!Contains(foo)` normalization in `QueryOptimizingExpressionVisitor` when `foo` references `i`, since `foo` would otherwise be moved out of the lambda
- Such queries now go through the regular `Any`/`All` translation (`EXISTS` / `NOT EXISTS`)
- Add tests with SQL baselines for SQLite, SQL Server (including JSON type and old compatibility level) and Cosmos

Fixes dotnet#39351

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@bkoelman

Copy link
Copy Markdown
Contributor Author

The Cosmos-windows build failure is unrelated to my changes; it also fails on main.

@bkoelman
bkoelman marked this pull request as ready for review November 29, 2026 12:17
@bkoelman
bkoelman requested a review from a team as a code owner November 29, 2026 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant