protected internal override Expression VisitCase(CaseExpression cex)
        {
            AppendNewLine(Indentation.Inner);
            sb.Append("CASE");
            AppendNewLine(Indentation.Inner);
            for (int i = 0, n = cex.Whens.Count; i < n; i++)
            {
                When when = cex.Whens[i];
                sb.Append("WHEN ");
                Visit(when.Condition);
                sb.Append(" THEN ");
                Visit(when.Value);
                AppendNewLine(Indentation.Same);
            }
            if (cex.DefaultValue != null)
            {
                sb.Append("ELSE ");
                Visit(cex.DefaultValue);
                AppendNewLine(Indentation.Outer);
            }
            sb.Append("END");
            AppendNewLine(Indentation.Outer);

            return(cex);
        }
Beispiel #2
0
        Expression MakeSqlValue(Expression exp)
        {
            if (exp == null)
            {
                return(null !);
            }

            if (!inSql || !IsBooleanExpression(exp))
            {
                return(exp);
            }

            if (exp.NodeType == ExpressionType.Constant)
            {
                switch (((bool?)((ConstantExpression)exp).Value))
                {
                case false: return(new SqlConstantExpression(0, exp.Type));

                case true: return(new SqlConstantExpression(1, exp.Type));

                case null: return(new SqlConstantExpression(null, exp.Type));
                }
                throw new InvalidOperationException("Entity");
            }

            if (!IsSqlCondition(exp))
            {
                return(exp);
            }

            var result = new CaseExpression(new[] { new When(exp, new SqlConstantExpression(true)) }, new SqlConstantExpression(false));

            return(exp.Type.IsNullable() ? result.Nullify() : result);
        }
Beispiel #3
0
        protected internal virtual Expression VisitCase(CaseExpression cex)
        {
            var newWhens   = Visit(cex.Whens, w => VisitWhen(w));
            var newDefault = Visit(cex.DefaultValue);

            if (newWhens != cex.Whens || newDefault != cex.DefaultValue)
            {
                return(new CaseExpression(newWhens, newDefault));
            }
            return(cex);
        }
Beispiel #4
0
        protected internal override Expression VisitCase(CaseExpression cex)
        {
            var newWhens   = Visit(cex.Whens, w => VisitWhen(w));
            var newDefault = MakeSqlValue(Visit(cex.DefaultValue));

            if (newWhens != cex.Whens || newDefault != cex.DefaultValue)
            {
                return(new CaseExpression(newWhens, newDefault));
            }
            return(cex);
        }
Beispiel #5
0
 protected virtual bool CompareCase(CaseExpression a, CaseExpression b)
 {
     return(CompareList(a.Whens, b.Whens, CompareWhen) &&
            Compare(a.DefaultValue, b.DefaultValue));
 }