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

Entity Equality: ArrayLength is not an entity reference #19431

Closed
smitpatel opened this issue Dec 30, 2019 · 1 comment · Fixed by #20447
Closed

Entity Equality: ArrayLength is not an entity reference #19431

smitpatel opened this issue Dec 30, 2019 · 1 comment · Fixed by #20447
Assignees
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@smitpatel
Copy link
Member

        [ConditionalTheory]
        [MemberData(nameof(IsAsyncData))]
        public virtual Task Where_ToArray_Length_member(bool async)
        {
            return AssertQuery(
                async,
                ss => ss.Set<Customer>().Select(c => ss.Set<Order>().Where(o => o.CustomerID == c.CustomerID).ToArray())
                    .Where(e => e.Length == 0));
        }

It incorrectly identifies e.Length as entity reference and tries to rewrite it to entity equality which fails.

 Message: 
    System.ArgumentException : Expression of type 'System.Int32' cannot be used for parameter of type 'System.Object' of method 'System.Nullable`1[System.Int32] Property[Nullable`1](System.Object, System.String)' (Parameter 'arg0')
  Stack Trace: 
    ExpressionUtils.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arguments, ParameterInfo pi, String methodParamName, String argumentParamName, Int32 index)
    Expression.Call(MethodInfo method, Expression arg0, Expression arg1)
    EFPropertyExtensions.CreateEFPropertyExpression(Expression target, Type propertyDeclaringType, Type propertyType, String propertyName, Boolean makeNullable) line 135
    EFPropertyExtensions.CreateEFPropertyExpression(Expression target, IPropertyBase property, Boolean makeNullable) line 103
    EntityEqualityRewritingExpressionVisitor.CreatePropertyAccessExpression(Expression target, IProperty property) line 989
    EntityEqualityRewritingExpressionVisitor.CreateKeyAccessExpression(Expression target, IReadOnlyList`1 properties) line 943
    EntityEqualityRewritingExpressionVisitor.RewriteEntityEquality(Boolean equality, IEntityType entityType, Expression left, INavigation leftNavigation, Expression right, INavigation rightNavigation, Boolean subqueryTraversed) line 923
    EntityEqualityRewritingExpressionVisitor.RewriteEquality(Boolean equality, Expression left, Expression right) line 847
    EntityEqualityRewritingExpressionVisitor.VisitBinary(BinaryExpression binaryExpression) line 186
    BinaryExpression.Accept(ExpressionVisitor visitor)
    ExpressionVisitor.Visit(Expression node)
    EntityEqualityRewritingExpressionVisitor.RewriteAndVisitLambda(LambdaExpression lambda, EntityReferenceExpression source) line 762
    EntityEqualityRewritingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression) line 366
    MethodCallExpression.Accept(ExpressionVisitor visitor)
    ExpressionVisitor.Visit(Expression node)
    EntityEqualityRewritingExpressionVisitor.Rewrite(Expression expression) line 52
    QueryTranslationPreprocessor.Process(Expression query) line 38
    QueryCompilationContext.CreateQueryExecutor[TResult](Expression query) line 74
    Database.CompileQuery[TResult](Expression query, Boolean async) line 71
    QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async) line 112
    <>c__DisplayClass9_0`1.<Execute>b__0() line 96
    CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler) line 84
    CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler) line 59
    QueryCompiler.Execute[TResult](Expression query) line 92
    EntityQueryProvider.Execute[TResult](Expression expression) line 79
    EntityQueryable`1.GetEnumerator() line 95
    LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
    EnumerableHelpers.ToArray[T](IEnumerable`1 source)
    Enumerable.ToArray[TSource](IEnumerable`1 source)
    QueryAsserter`1.AssertQuery[TResult](Func`2 actualQuery, Func`2 expectedQuery, Func`2 elementSorter, Action`2 elementAsserter, Boolean assertOrder, Int32 entryCount, Boolean async, String testMethodName) line 91
    --- End of stack trace from previous location where exception was thrown ---

@smitpatel
Copy link
Member Author

Related #20164

@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Mar 28, 2020
smitpatel added a commit that referenced this issue Mar 28, 2020
Resolves #15080
Implemented behavior:
- If any part of composite key is null then key is null.
- If comparing entity with null then check if "any" key value is null.
- If comparing entity with non-null then check if "all" key values are non null.

Resolves #20344
Resolves #19431
Resolves #13568
Resolves #13655
Since we already convert property access to nullable, if entity from client is null, make key value as null.

Resolves #19676
Clr type mismatch between proxy type and entity type is ignored.

Resolves #20164
Rewrites entity equality during translation

Part of #18923
smitpatel added a commit that referenced this issue Mar 28, 2020
Resolves #15080
Implemented behavior:
- If any part of composite key is null then key is null.
- If comparing entity with null then check if "any" key value is null.
- If comparing entity with non-null then check if "all" key values are non null.

Resolves #20344
Resolves #19431
Resolves #13568
Resolves #13655
Since we already convert property access to nullable, if entity from client is null, make key value as null.

Resolves #19676
Clr type mismatch between proxy type and entity type is ignored.

Resolves #20164
Rewrites entity equality during translation

Part of #18923
smitpatel added a commit that referenced this issue Mar 28, 2020
Resolves #15080
Implemented behavior:
- If any part of composite key is null then key is null.
- If comparing entity with null then check if "any" key value is null.
- If comparing entity with non-null then check if "all" key values are non null.

Resolves #20344
Resolves #19431
Resolves #13568
Resolves #13655
Since we already convert property access to nullable, if entity from client is null, make key value as null.

Resolves #19676
Clr type mismatch between proxy type and entity type is ignored.

Resolves #20164
Rewrites entity equality during translation

Part of #18923
smitpatel added a commit that referenced this issue Mar 31, 2020
Resolves #15080
Implemented behavior:
- If any part of composite key is null then key is null.
- If comparing entity with null then check if "any" key value is null.
- If comparing entity with non-null then check if "all" key values are non null.

Resolves #20344
Resolves #19431
Resolves #13568
Resolves #13655
Since we already convert property access to nullable, if entity from client is null, make key value as null.

Resolves #19676
Clr type mismatch between proxy type and entity type is ignored.

Resolves #20164
Rewrites entity equality during translation

Part of #18923
smitpatel added a commit that referenced this issue Mar 31, 2020
Resolves #15080
Implemented behavior:
- If any part of composite key is null then key is null.
- If comparing entity with null then check if "any" key value is null.
- If comparing entity with non-null then check if "all" key values are non null.

Resolves #20344
Resolves #19431
Resolves #13568
Resolves #13655
Since we already convert property access to nullable, if entity from client is null, make key value as null.

Resolves #19676
Clr type mismatch between proxy type and entity type is ignored.

Resolves #20164
Rewrites entity equality during translation

Part of #18923
@ajcvickers ajcvickers modified the milestones: 5.0.0, 5.0.0-preview3 Mar 31, 2020
@smitpatel smitpatel modified the milestones: 5.0.0-preview3, 5.0.0 Apr 1, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0, 5.0.0-preview4 Apr 20, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0-preview4, 5.0.0 Nov 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants