protected override Expression VisitIn(InExpression inExpression)
        {
            if (inExpression.Values is SqlParameterExpression spe)
            {
                var plist = queryContext.ParameterValues[spe.Name] as System.Collections.IList;

                // inExpression.Item

                // sqlFactory.a

                // var ce = sqlFactory.Constant(plist.Select(x => (object));

                List <object> list = new List <object>();
                foreach (var item in plist)
                {
                    list.Add(item);
                }

                var ce = sqlFactory.Constant(list, sqlFactory.GetTypeMappingForValue(list.FirstOrDefault()));

                // sqlFactory.MakeBinary(ExpressionType.or)



                return(inExpression.Update(inExpression.Item, ce, inExpression.Subquery));

                //var _relationalCommandBuilder = this.GetPrivateField<IRelationalCommandBuilder>("_relationalCommandBuilder");
                //_relationalCommandBuilder.Append(inExpression.IsNegated ? " NOT IN " : " IN ");
                //_relationalCommandBuilder.Append("(");
                //// _relationalCommandBuilder.Append(spe.Name);

                //// we need to expand our list here...
                //var prefix = spe.Name;

                //var plist = queryContext.ParameterValues[spe.Name] as System.Collections.IList;
                //int i = 0;
                //foreach(var pv in plist)
                //{
                //    var n = $"{prefix}_{i}";
                //    queryContext.AddParameter(n, pv);
                //    if (i != 0)
                //    {
                //        _relationalCommandBuilder.Append(", ");
                //    }
                //    _relationalCommandBuilder.AppendLine($"@{n}");
                //    i++;
                //}

                //_relationalCommandBuilder.Append(")");
                // return inExpression;
            }

            return(inExpression);
        }
            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);
            }
        private Expression DoDecimalCompare(SqlExpression visitedExpression, ExpressionType op, SqlExpression left, SqlExpression right)
        {
            var actual = SqlExpressionFactory.Function(
                name: "ef_compare",
                new[] { left, right },
                nullable: true,
                new[] { true, true },
                typeof(int));
            var oracle = SqlExpressionFactory.Constant(value: 0);

            return(op switch
            {
                ExpressionType.GreaterThan => SqlExpressionFactory.GreaterThan(left: actual, right: oracle),
                ExpressionType.GreaterThanOrEqual => SqlExpressionFactory.GreaterThanOrEqual(left: actual, right: oracle),
                ExpressionType.LessThan => SqlExpressionFactory.LessThan(left: actual, right: oracle),
                ExpressionType.LessThanOrEqual => SqlExpressionFactory.LessThanOrEqual(left: actual, right: oracle),
                _ => visitedExpression
            });
            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));
            }
            protected override Expression VisitSqlUnaryExpression(SqlUnaryExpression sqlUnaryExpression)
            {
                var result = base.VisitSqlUnaryExpression(sqlUnaryExpression);

                if (result is SqlUnaryExpression newUnaryExpression &&
                    newUnaryExpression.Operand is SqlParameterExpression parameterOperand)
                {
                    var parameterValue = _parametersValues[parameterOperand.Name];
                    if (sqlUnaryExpression.OperatorType == ExpressionType.Equal)
                    {
                        return(SqlExpressionFactory.Constant(parameterValue == null, sqlUnaryExpression.TypeMapping));
                    }

                    if (sqlUnaryExpression.OperatorType == ExpressionType.NotEqual)
                    {
                        return(SqlExpressionFactory.Constant(parameterValue != null, sqlUnaryExpression.TypeMapping));
                    }
                }

                return(result);
            }