efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Unary expression visitation throws for certain 'Not (!)' subqueries

Open EricABC opened this issue 11 years ago • 3 comments

In SqlTranslatingExpressionVisitor: https://github.com/aspnet/EntityFramework/blob/dev/src/EntityFramework.Relational/Query/ExpressionVisitors/SqlTranslatingExpressionVisitor.cs#L327

VisitUnary throws for a null operand in the 'ExpressionType.Not' case. This where clause: .Where(t => !t.UpstreamTenantRelationships.Any()) will fail in this case. However, .Where(t => t.UpstreamTenantRelationships.Count() == 0) will succeed. The Count version results in VisitBinary returning null to the VisitWhereClause method in RelationalQueryModelVisitor.

Changing VisitUnary similar to below resulted in the query executing correctly.

            case ExpressionType.Not:
            {
                var operand = Visit(expression.Operand);
                if (operand == null)
                    break;
                return Expression.Not(operand);
            }

EricABC avatar Jul 10 '15 21:07 EricABC

@maumar this looks like something in your area.

divega avatar Jul 10 '15 23:07 divega

Navigation property translation is a work in progress. Leaving open to verify this particular scenario once that is working.

rowanmiller avatar Jul 14 '15 18:07 rowanmiller

Fixed in d2802fdaf35458e35a69f9573e57c592d43c6367

maumar avatar Sep 24 '15 01:09 maumar