protected override Expression VisitExtension(Expression extensionExpression)
            {
                // workaround for issue #18492
                var newExpression = base.VisitExtension(extensionExpression);

                if (newExpression is SelectExpression newSelectExpression)
                {
                    var changed      = false;
                    var newPredicate = newSelectExpression.Predicate;
                    var newHaving    = newSelectExpression.Having;
                    if (newSelectExpression.Predicate is SqlConstantExpression predicateConstantExpression &&
                        predicateConstantExpression.Value is bool predicateBoolValue &&
                        !predicateBoolValue)
                    {
                        changed      = true;
                        newPredicate = SqlExpressionFactory.Equal(
                            predicateConstantExpression,
                            SqlExpressionFactory.Constant(true, predicateConstantExpression.TypeMapping));
                    }

                    if (newSelectExpression.Having is SqlConstantExpression havingConstantExpression &&
                        havingConstantExpression.Value is bool havingBoolValue &&
                        !havingBoolValue)
                    {
                        changed   = true;
                        newHaving = SqlExpressionFactory.Equal(
                            havingConstantExpression,
                            SqlExpressionFactory.Constant(true, havingConstantExpression.TypeMapping));
                    }

                    return(changed
                        ? newSelectExpression.Update(
                               newSelectExpression.Projection.ToList(),
                               newSelectExpression.Tables.ToList(),
                               newPredicate,
                               newSelectExpression.GroupBy.ToList(),
                               newHaving,
                               newSelectExpression.Orderings.ToList(),
                               newSelectExpression.Limit,
                               newSelectExpression.Offset,
                               newSelectExpression.IsDistinct,
                               newSelectExpression.Alias)
                        : newSelectExpression);
                }

                return(newExpression);
            }
            protected override Expression VisitExtension(Expression extensionExpression)
            {
                if (extensionExpression is SelectExpression selectExpression)
                {
                    var newSelectExpression = (SelectExpression)base.VisitExtension(extensionExpression);

                    // if predicate is optimized to true, we can simply remove it
                    var newPredicate = newSelectExpression.Predicate is SqlConstantExpression newSelectPredicateConstant &&
                                       !(selectExpression.Predicate is SqlConstantExpression)
                            ? (bool)newSelectPredicateConstant.Value
                                ? null
                                : SqlExpressionFactory.Equal(
                        newSelectPredicateConstant,
                        SqlExpressionFactory.Constant(true, newSelectPredicateConstant.TypeMapping))
                            : newSelectExpression.Predicate;

                    var newHaving = newSelectExpression.Having is SqlConstantExpression newSelectHavingConstant &&
                                    !(selectExpression.Having is SqlConstantExpression)
                            ? (bool)newSelectHavingConstant.Value
                                ? null
                                : SqlExpressionFactory.Equal(
                        newSelectHavingConstant,
                        SqlExpressionFactory.Constant(true, newSelectHavingConstant.TypeMapping))
                            : newSelectExpression.Having;

                    return(!ReferenceEquals(newPredicate, newSelectExpression.Predicate) ||
                           !ReferenceEquals(newHaving, newSelectExpression.Having)
                            ? newSelectExpression.Update(
                               newSelectExpression.Projection.ToList(),
                               newSelectExpression.Tables.ToList(),
                               newPredicate,
                               newSelectExpression.GroupBy.ToList(),
                               newHaving,
                               newSelectExpression.Orderings.ToList(),
                               newSelectExpression.Limit,
                               newSelectExpression.Offset,
                               newSelectExpression.IsDistinct,
                               newSelectExpression.Alias)
                            : newSelectExpression);
                }

                return(base.VisitExtension(extensionExpression));
            }