Example #1
0
        protected override Expression VisitConstantExpression(ConstantExpression expression)
        {
            var value = expression.Value;
            var type  = value != null?value.GetType() : expression.Type;

            var toBooleanCompare = (type == typeof(bool) || type == typeof(bool?)) && (BinaryLevel == 0 && Level == 1 || BinaryLevel + 1 < Level);

            if (toBooleanCompare && value is bool)
            {
                SqlExpression.Append(" (1 = ");
                if ((bool)value)
                {
                    SqlExpression.Append("1)");
                }
                else
                {
                    SqlExpression.Append("0)");
                }
            }
            else
            {
                SqlExpression.Append(QueryParts.AddParameter(type, value, Context.CanUseParams));

                if (toBooleanCompare)
                {
                    SqlExpression.Append(" = 'Y'");
                }
            }
            return(expression);
        }
        protected override Expression VisitConstantExpression(ConstantExpression expression)
        {
            var value = expression.Value;
            var type  = value != null?value.GetType() : expression.Type;

            SqlExpression.Append(QueryParts.AddParameter(type, value, Context.CanUseParams));

            if ((type == typeof(bool) || type == typeof(bool?)) && (BinaryLevel == 0 && Level == 1 || BinaryLevel + 1 < Level))
            {
                SqlExpression.Append(" = 'Y'");
            }

            return(expression);
        }