Equality() 공개 메소드

public Equality ( HqlExpression lhs, HqlExpression rhs ) : HqlEquality
lhs HqlExpression
rhs HqlExpression
리턴 HqlEquality
        public override HqlTreeNode BuildHql(
            MethodInfo method,
            Expression targetObject,
            ReadOnlyCollection<Expression> arguments,
            HqlTreeBuilder treeBuilder,
            IHqlExpressionVisitor visitor)
        {
            // Get the StringComparison argument.
            var comparison = (StringComparison)(arguments[1].As<ConstantExpression>().Value);

            if (comparison == StringComparison.CurrentCultureIgnoreCase
                || comparison == StringComparison.InvariantCultureIgnoreCase
                || comparison == StringComparison.OrdinalIgnoreCase)
            {
                // If the comparison calls for us to ignore the case, use SQL LOWER()
                return
                    treeBuilder.Equality(
                        treeBuilder.MethodCall("lower", new[] { visitor.Visit(targetObject).AsExpression() }),
                        treeBuilder.MethodCall("lower", new[] { visitor.Visit(arguments[0]).AsExpression() }));
            }

            // Otherwise use the database's default string comparison mechanism.
            return treeBuilder.Equality(
                visitor.Visit(targetObject).AsExpression(),
                visitor.Visit(arguments[0]).AsExpression());
        }
 public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
 {
     var comparison = (StringComparison)(arguments[1].As<ConstantExpression>().Value);
     if (comparison == StringComparison.CurrentCultureIgnoreCase ||
         comparison == StringComparison.InvariantCultureIgnoreCase ||
         comparison == StringComparison.OrdinalIgnoreCase)
     {
         return treeBuilder.Equality(
             treeBuilder.MethodCall("lower", new[] { visitor.Visit(targetObject).AsExpression() }),
             treeBuilder.MethodCall("lower", new[] { visitor.Visit(arguments[0]).AsExpression() }));
     }
     return treeBuilder.Equality(
         visitor.Visit(targetObject).AsExpression(),
         visitor.Visit(arguments[0]).AsExpression());
 }
예제 #3
0
 public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
 {
     HqlExpression targetExpression = visitor.Visit(targetObject).AsExpression();
     HqlExpression argument0Expression = visitor.Visit(arguments[0]).AsExpression();
     HqlEquality result = treeBuilder.Equality(targetExpression, argument0Expression);
     return result;
 }
예제 #4
0
 public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject,
     ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
 {
     return treeBuilder.Equality(
         visitor.Visit(targetObject).AsExpression(),
         visitor.Visit(arguments[0]).AsExpression());
 }
예제 #5
0
		public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
		{
			// HqlGeneratorExpressionTreeVisitor.VisitConstantExpression will always return an HqlEquality 
			// instead of HqlParameter for argument that is of type bool.
			// Use the HqlParameter that exists as first children to the HqlEquality as second argument into treeBuilder.Equality
			return treeBuilder.Equality(
				visitor.Visit(targetObject).AsExpression(),
				visitor.Visit(arguments[0]).Children.First().AsExpression());
		}
예제 #6
0
		public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
		{
			Expression lhs = arguments.Count == 1 ? targetObject : arguments[0];
			Expression rhs = arguments.Count == 1 ? arguments[0] : arguments[1];

			return treeBuilder.Equality(
				visitor.Visit(lhs).AsExpression(),
				visitor.Visit(rhs).AsExpression());
		}
		public override HqlTreeNode BuildHql(
			MethodInfo method,
			Expression targetObject,
			ReadOnlyCollection<Expression> arguments,
			HqlTreeBuilder treeBuilder,
			IHqlExpressionVisitor visitor)
		{
			var left = treeBuilder.Cast(visitor.Visit(targetObject).AsExpression(), typeof(string));
			var right = treeBuilder.Cast(visitor.Visit(arguments.First()).AsExpression(), typeof(string));

			var leftSubstring = treeBuilder.MethodCall("substring", left, treeBuilder.Constant(4));
			var rightSubstring = treeBuilder.MethodCall("substring", right, treeBuilder.Constant(4));
			var equals = treeBuilder.Equality(leftSubstring, rightSubstring);
			return equals;
		}
예제 #8
0
        public static HqlBooleanExpression ToBooleanExpression(this HqlTreeNode node)
        {
            var hqlDot = node as HqlDot;

            if (hqlDot != null)
            {
                return(new HqlBooleanDot(hqlDot.Factory, hqlDot));
            }
            var hqlBooleanExpression = node as HqlBooleanExpression;

            if (hqlBooleanExpression != null)
            {
                return(hqlBooleanExpression);
            }

            var builder = new HqlTreeBuilder();

            return(builder.Equality(node.AsExpression(), builder.True()));
        }
예제 #9
0
		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));
		}
예제 #10
0
        ///<summary>
        ///
        ///</summary>
        ///<param name="method"></param>
        ///<param name="targetObject">Should be an ISecurable</param>
        ///<param name="arguments">Not sure what the heck arg[0] is, but arg[1] is the entityName</param>
        ///<param name="treeBuilder"></param>
        ///<param name="visitor"></param>
        ///<returns></returns>
        public override HqlTreeNode BuildHql(
            MethodInfo method,
            Expression targetObject,
            ReadOnlyCollection<Expression> arguments,
            HqlTreeBuilder treeBuilder,
            IHqlExpressionVisitor visitor)
        {
            // arguments[0] is a System.Linq.Expressions.Expression
            // arguments[1] is our constant value
            var expr = arguments[0];

            // This doesn't really help us right now, but log it just in case...
            if (expr is Remotion.Linq.Clauses.Expressions.QuerySourceReferenceExpression)
            {
                Console.WriteLine(
                    "ReferencedQuerySource: {0}",
                    ((Remotion.Linq.Clauses.Expressions.QuerySourceReferenceExpression)expr).ReferencedQuerySource
                );
            }

            // Getting somewhere?
            // expr.Type is Spc.Ofp.Tubs.DAL.Entities.Trip
            Console.WriteLine("Expression type: {0}", expr.Type);

            // HqlAlias is "AccessControl" (entity property), "ace" (name used in expression) ?
            // HqlExpression is equality expression ?
            var aceAlias = treeBuilder.Alias("AccessControl as ace");

            var entityName = ((ConstantExpression)arguments[1]).Value;

            Console.WriteLine("entityName: {0}", entityName);

            var equality = treeBuilder.Equality(
                treeBuilder.Alias("ace.EntityName"),
                treeBuilder.Constant(entityName)
            );

            var joinExpression = treeBuilder.Join(equality, aceAlias);

            // This doesn't actually do anything...
            return visitor.Visit(expr).AsExpression();

            /*
             * var dc =
                DetachedCriteria.For<T>()
                                .CreateAlias("AccessControl", "ace", JoinType.InnerJoin)
                                .Add(NHibernate.Criterion.Expression.Eq("ace.EntityName", this._entityName));
             */
        }
 public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject,
     ReadOnlyCollection<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
 {
     var constantParameter = arguments[1] as ConstantExpression;
     if (constantParameter != null && constantParameter.Value == null)
         return treeBuilder.IsNull(visitor.Visit(arguments[0]).AsExpression());
     else
         return treeBuilder.Equality(
             visitor.Visit(arguments[0]).AsExpression(),
             visitor.Visit(arguments[1]).AsExpression());
 }