Пример #1
0
    protected internal virtual Expression VisitSqlCast(SqlCastExpression castExpr)
    {
        var expression = Visit(castExpr.Expression);

        if (expression != castExpr.Expression)
        {
            return(new SqlCastExpression(castExpr.Type, expression, castExpr.DbType));
        }
        return(castExpr);
    }
Пример #2
0
    protected internal override Expression VisitSqlCast(SqlCastExpression castExpr)
    {
        sb.Append("CAST(");
        Visit(castExpr.Expression);
        sb.Append(" as ");
        sb.Append(castExpr.DbType.ToString(schema.Settings.IsPostgres));

        if (!schema.Settings.IsPostgres && (castExpr.DbType.SqlServer == SqlDbType.NVarChar || castExpr.DbType.SqlServer == SqlDbType.VarChar))
        {
            sb.Append("(MAX)");
        }

        sb.Append(')');
        return(castExpr);
    }
    protected internal override Expression VisitSqlCast(SqlCastExpression castExpr)
    {
        var expression = Visit(castExpr.Expression);

        if (expression.Type.UnNullify() == typeof(bool) && castExpr.Type.UnNullify() != typeof(int))
        {
            return(new SqlCastExpression(castExpr.Type, new SqlCastExpression(typeof(int), expression), castExpr.DbType));
        }

        if (expression != castExpr.Expression)
        {
            return(new SqlCastExpression(castExpr.Type, expression, castExpr.DbType));
        }

        return(castExpr);
    }
        protected override Expression VisitMethodCall(MethodCallExpression node)
        {
            var @object   = Visit(node.Object);
            var arguments = Visit(node.Arguments);

            if (generalMathMethods.TryGetValue(node.Method, out var sqlFunctionName))
            {
                return(new SqlFunctionExpression(sqlFunctionName, node.Type, arguments.ToArray()));
            }
            else if (truncateMethods.Contains(node.Method))
            {
                var firstArgument = arguments[0];

                if (firstArgument.NodeType == ExpressionType.Convert)
                {
                    firstArgument = new SqlCastExpression(firstArgument, firstArgument.Type);
                }

                return(new SqlFunctionExpression(
                           "ROUND",
                           node.Type,
                           new[] { firstArgument, Expression.Constant(0), Expression.Constant(1) }));
            }
            else if (roundMethods.Contains(node.Method))
            {
                var firstArgument = arguments[0];

                if (firstArgument.NodeType == ExpressionType.Convert)
                {
                    firstArgument = new SqlCastExpression(firstArgument, firstArgument.Type);
                }

                return(new SqlFunctionExpression(
                           "ROUND",
                           node.Type,
                           arguments.Count == 1
                        ? new[] { firstArgument, Expression.Constant(0) }
                        : new[] { firstArgument, arguments[1] }));
            }

            return(node.Update(@object, arguments));
        }
Пример #5
0
 public override void Visit(SqlCastExpression codeObject)
 {
 }
Пример #6
0
 protected virtual Expression VisitSqlCast(SqlCastExpression castExpr)
 {
     var expression = Visit(castExpr.Expression);
     if (expression != castExpr.Expression)
         return new SqlCastExpression(castExpr.Type, expression,castExpr.SqlDbType);
     return castExpr;
 }
Пример #7
0
 protected internal override Expression VisitSqlCast(SqlCastExpression castExpr)
 {
     var expression = MakeSqlValue(Visit(castExpr.Expression));
     if (expression != castExpr.Expression)
         return new SqlCastExpression(castExpr.Type, expression, castExpr.SqlDbType);
     return castExpr;
 }
Пример #8
0
 private void GenerateCast(SqlGenerator sql, SqlCastExpression cast)
 {
     sql.Add("CAST(");
     GenerateField(sql, cast.Field);
     sql.Add($" AS {FieldToStr(cast.FieldType)})");
 }
Пример #9
0
 protected override Expression VisitSqlCast(SqlCastExpression castExpr)
 {
     sb.Append("CAST(");
     Visit(castExpr.Expression);
     sb.Append(" as ");
     sb.Append(castExpr.SqlDbType.ToString().ToUpperInvariant());
     sb.Append(")");
     return castExpr;
 }