Skip to content

QueryableMethodNormalizingExpressionVisitor does not visit recursively when converting List.Contains to Queryable.Contains #32215

Closed

Description

@roji

Test PrimitiveCollectionsQuerySqlServerTest.Nested_contains_with_Lists_and_no_inferred_type_mapping) has a nested Contains case with array parameter parameters, where the inner contains gets translated via the old-style constant expansion rather than as a parameter query root (i.e. with OPENJSON):

[ConditionalTheory] // #32208
[MemberData(nameof(IsAsyncData))]
public virtual Task Nested_contains_with_Lists_and_no_inferred_type_mapping(bool async)
{
    var ints = new List<int> { 1, 2, 3 };
    var strings = new List<string> { "one", "two", "three" };

    // Note that in this query, the outer Contains really has no type mapping, neither for its source (collection parameter), nor
    // for its item (the conditional expression returns constants). The default type mapping must be applied.
    return AssertQuery(
        async,
        ss => ss.Set<PrimitiveCollectionsEntity>().Where(e => strings.Contains(ints.Contains(e.Int) ? "one" : "two")));
}

SQL:

SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[String], [p].[Strings]
FROM [PrimitiveCollectionsEntity] AS [p]
WHERE CASE
    WHEN [p].[Int] IN (1, 2, 3) THEN N'one'
    ELSE N'two'
END IN (
    SELECT [s].[value]
    FROM OPENJSON(@__strings_0) WITH ([value] nvarchar(max) '$') AS [s]
)

Activity

  1. self-assigned this
    on Nov 2, 2023
  2. changed the title [-]Array parameter isn't translated as a primitive collection in some cases[/-] [+]QueryableMethodNormalizingExpressionVisitor does not visit recursively when converting List.Contains to Queryable.Contains[/+] on Nov 2, 2023
  3. added a commit that references this issue on Nov 2, 2023
    4b9280c
  4. added a commit that references this issue on Nov 3, 2023
    7fe11ed
  5. added a commit that references this issue on Nov 3, 2023
    08ee676
  6. roji commented on Nov 3, 2023

    @roji
    MemberAuthor

    Reopening to discuss patching 8.0

  7. reopened this on Nov 3, 2023
  8. added 3 commits that reference this issue on Nov 9, 2023
    5eee914
    85268a4
    7c8127b
  9. added this to the 8.0.1 milestone on Nov 13, 2023
  10. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions