コード例 #1
0
        public void CreateIfThenElseNull()
        {
            var result = SqlCaseExpression.CreateIfThenElseNull(typeof(int?), _predicate1, _value1, _value2);

            Assert.That(result.Cases, Has.Count.EqualTo(2));
            Assert.That(result.Cases[0].When, Is.SameAs(_predicate1));
            Assert.That(result.Cases[0].Then, Is.SameAs(_value1));
            SqlExpressionTreeComparer.CheckAreEqualTrees(result.Cases[1].When, Expression.Not(_predicate1));
            Assert.That(result.Cases[1].Then, Is.SameAs(_value2));
            SqlExpressionTreeComparer.CheckAreEqualTrees(result.ElseCase, Expression.Constant(null, typeof(int?)));
        }
コード例 #2
0
 private Expression CreateValueExpressionForPredicate(Expression predicate)
 {
     // If the predicate is nullable, we have three cases (true, false, null). Otherweise, we just have two cases.
     if (predicate.Type == typeof(bool?))
     {
         return(SqlCaseExpression.CreateIfThenElseNull(typeof(int?), predicate, new SqlLiteralExpression(1), new SqlLiteralExpression(0)));
     }
     else
     {
         return(SqlCaseExpression.CreateIfThenElse(typeof(int), predicate, new SqlLiteralExpression(1), new SqlLiteralExpression(0)));
     }
 }