Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
roji opened this issue Nov 2, 2023 · 1 comment · Fixed by #32219
Assignees
Labels
area-perf area-primitive-collections area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. Servicing-approved type-bug
Milestone

Comments

@roji
Copy link
Member

roji commented Nov 2, 2023

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]
)
@roji roji self-assigned this Nov 2, 2023
@roji roji added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Nov 2, 2023
@roji roji 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 Nov 2, 2023
roji added a commit to roji/efcore that referenced this issue Nov 2, 2023
roji added a commit to roji/efcore that referenced this issue Nov 3, 2023
roji added a commit that referenced this issue Nov 3, 2023
@roji
Copy link
Member Author

roji commented Nov 3, 2023

Reopening to discuss patching 8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-perf area-primitive-collections area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. Servicing-approved type-bug
Projects
None yet
2 participants