Exemplo n.º 1
0
        protected internal override Expression VisitSqlConstant(SqlConstantExpression c)
        {
            if (c.Value == null)
            {
                sb.Append("NULL");
            }
            else
            {
                if (!Schema.Current.Settings.IsDbType(c.Value.GetType().UnNullify()))
                {
                    throw new NotSupportedException(string.Format("The constant for {0} is not supported", c.Value));
                }

                if (c.Value.Equals(true))
                {
                    sb.Append("1");
                }
                else if (c.Value.Equals(false))
                {
                    sb.Append("0");
                }
                else if (c.Value is string)
                {
                    sb.Append(((string)c.Value == "") ? "''" : ("'" + c.Value + "'"));
                }
                else
                {
                    sb.Append(c.ToString());
                }
            }

            return(c);
        }
Exemplo n.º 2
0
        protected internal override Expression VisitSqlConstant(SqlConstantExpression c)
        {
            if (c.Value == null)
            {
                sb.Append("NULL");
            }
            else
            {
                if (!schema.Settings.IsDbType(c.Value.GetType().UnNullify()))
                {
                    throw new NotSupportedException(string.Format("The constant for {0} is not supported", c.Value));
                }

                if (!isPostgres && c.Value.Equals(true))
                {
                    sb.Append('1');
                }
                else if (!isPostgres && c.Value.Equals(false))
                {
                    sb.Append('0');
                }
                else if (c.Value is string s)
                {
                    sb.Append(s == "" ? "''" : ("'" + s + "'"));
                }
                else if (c.Value is TimeSpan ts)
                {
                    sb.Append(@$ "CONVERT(time, '{ts}')");
                }
                else
                {
                    sb.Append(c.ToString());
                }
            }

            return(c);
        }