예제 #1
0
            /// <summary>
            /// Helper for VisitBinaryOperator. Builds the new case with distributed valueds.
            /// </summary>
            private SqlExpression DistributeOperatorIntoCase(SqlNodeType nt, SqlSimpleCase sc, SqlExpression expr)
            {
                if (nt != SqlNodeType.EQ && nt != SqlNodeType.NE && nt != SqlNodeType.EQ2V && nt != SqlNodeType.NE2V)
                {
                    throw Error.ArgumentOutOfRange("nt");
                }
                object val = Eval(expr);
                List <SqlExpression> values  = new List <SqlExpression>();
                List <SqlExpression> matches = new List <SqlExpression>();

                foreach (SqlWhen when in sc.Whens)
                {
                    matches.Add(when.Match);
                    object whenVal = Eval(when.Value);
                    bool   eq      = when.Value.SqlType.AreValuesEqual(whenVal, val);
                    values.Add(sql.ValueFromObject((nt == SqlNodeType.EQ || nt == SqlNodeType.EQ2V) == eq, false, sc.SourceExpression));
                }
                return(this.VisitExpression(sql.Case(typeof(bool), sc.Expression, matches, values, sc.SourceExpression)));
            }