Case() public method

public Case ( HqlWhen whenClauses ) : HqlCase
whenClauses HqlWhen
return HqlCase
コード例 #1
0
ファイル: HqlTreeNode.cs プロジェクト: tker/nhibernate-core
        internal static HqlExpression ToArithmeticExpression(this HqlTreeNode node)
        {
            var hqlBooleanExpression = node as HqlBooleanExpression;

            if (hqlBooleanExpression != null)
            {
                var builder = new HqlTreeBuilder();

                return(builder.Case(new[] { builder.When(hqlBooleanExpression, builder.True()) }, builder.False()));
            }

            return((HqlExpression)node);
        }
コード例 #2
0
		public static HqlExpression ConvertBooleanToCase(HqlExpression node)
		{
			if (node is HqlBooleanExpression)
			{
				var builder = new HqlTreeBuilder();

				return builder.Case(
					new[] {builder.When(node, builder.True())},
					builder.False());
			}

			return node;
		}
コード例 #3
0
 public override NHibernate.Hql.Ast.HqlTreeNode BuildHql(System.Reflection.MethodInfo method, System.Linq.Expressions.Expression targetObject, System.Collections.ObjectModel.ReadOnlyCollection <System.Linq.Expressions.Expression> arguments, NHibernate.Hql.Ast.HqlTreeBuilder treeBuilder, NHibernate.Linq.Visitors.IHqlExpressionVisitor visitor)
 {
     //return treeBuilder.Constant(0);
     return(treeBuilder.Case(new HqlWhen[] {
         treeBuilder.When(
             treeBuilder.LessThan(visitor.Visit(arguments[0]).AsExpression(), visitor.Visit(arguments[1]).AsExpression()),
             treeBuilder.Constant(-1)),
         treeBuilder.When(
             treeBuilder.GreaterThan(visitor.Visit(arguments[0]).AsExpression(), visitor.Visit(arguments[1]).AsExpression()),
             treeBuilder.Constant(1))
     },
                             treeBuilder.Constant(0)));
 }
コード例 #4
0
ファイル: CompareGenerator.cs プロジェクト: prime/nshibernate
		public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
		{
			// Instance CompareTo() or static string.Compare()?
			Expression lhs = arguments.Count == 1 ? targetObject : arguments[0];
			Expression rhs = arguments.Count == 1 ? arguments[0] : arguments[1];

			HqlExpression lhs1 = visitor.Visit(lhs).AsExpression();
			HqlExpression rhs1 = visitor.Visit(rhs).AsExpression();
			HqlExpression lhs2 = visitor.Visit(lhs).AsExpression();
			HqlExpression rhs2 = visitor.Visit(rhs).AsExpression();

			// CASE WHEN (table.[Name] = N'Foo') THEN 0
			//      WHEN (table.[Name] > N'Foo') THEN 1
			//      ELSE -1 END

			return treeBuilder.Case(
				new[]
					{
						treeBuilder.When(treeBuilder.Equality(lhs1, rhs1), treeBuilder.Constant(0)),
						treeBuilder.When(treeBuilder.GreaterThan(lhs2, rhs2), treeBuilder.Constant(1))
					},
				treeBuilder.Constant(-1));
		}