예제 #1
0
        public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection <Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
        {
            string trimWhere;

            if (method.Name == "TrimStart")
            {
                trimWhere = "leading";
            }
            else if (method.Name == "TrimEnd")
            {
                trimWhere = "trailing";
            }
            else
            {
                trimWhere = "both";
            }

            var trimChars = ExtractTrimChars(arguments);

            if (string.IsNullOrEmpty(trimChars))
            {
                return(treeBuilder.MethodCall("trim", treeBuilder.Ident(trimWhere), treeBuilder.Ident("from"), visitor.Visit(targetObject).AsExpression()));
            }
            else
            {
                return(treeBuilder.MethodCall("trim", treeBuilder.Ident(trimWhere), treeBuilder.Constant(trimChars), treeBuilder.Ident("from"), visitor.Visit(targetObject).AsExpression()));
            }
        }
예제 #2
0
 private HqlTreeNode VisitTypeBinaryExpression(TypeBinaryExpression expression)
 {
     return(_hqlTreeBuilder.Equality(
                _hqlTreeBuilder.Dot(
                    Visit(expression.Expression).AsExpression(),
                    _hqlTreeBuilder.Class()),
                _hqlTreeBuilder.Ident(expression.TypeOperand.FullName)));
 }
        private HqlTreeNode VisitDynamicExpression(DynamicExpression expression)
        {
            switch (expression.Binder)
            {
            case GetMemberBinder binder:
                return(_hqlTreeBuilder.Dot(
                           VisitExpression(expression.Arguments[0]).AsExpression(),
                           _hqlTreeBuilder.Ident(binder.Name)));
            }

            throw new NotSupportedException($"Dynamic expression with a binder of {expression.Binder.GetType()} is not supported");
        }
예제 #4
0
        public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection <Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
        {
            string leadingOrTrailing = "TRAILING";

            if (method.Name == "TrimLeading")
            {
                leadingOrTrailing = "LEADING";
            }

            return(treeBuilder.MethodCall("Trim",
                                          treeBuilder.Ident(leadingOrTrailing),
                                          visitor.Visit(arguments[1]).AsExpression(),
                                          treeBuilder.Ident("FROM"),
                                          visitor.Visit(arguments[0]).AsExpression()));
        }
        /// <summary>
        /// Overrides the BuildHql method to add an expression that supports Linq querying of the supported properties.
        /// </summary>
        public override HqlTreeNode BuildHql(MemberInfo member, Expression expression, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
        {
            var source   = visitor.Visit(expression).AsExpression();
            var property = treeBuilder.Ident("Currency");

            return(treeBuilder.Dot(source, property));
        }
예제 #6
0
        internal HqlBooleanExpression BuildOfType(Expression expression, System.Type type)
        {
            var sessionFactory = _parameters.SessionFactory;
            var meta           = sessionFactory.GetClassMetadata(type) as Persister.Entity.AbstractEntityPersister;

            if (meta != null && !meta.IsExplicitPolymorphism)
            {
                //Adapted the logic found in SingleTableEntityPersister.DiscriminatorFilterFragment
                var nodes = meta
                            .SubclassClosure
                            .Select(typeName => (NHibernate.Persister.Entity.IQueryable)sessionFactory.GetEntityPersister(typeName))
                            .Where(persister => !persister.IsAbstract)
                            .Select(persister => _hqlTreeBuilder.Ident(persister.EntityName))
                            .ToList();

                if (nodes.Count == 1)
                {
                    return(_hqlTreeBuilder.Equality(
                               _hqlTreeBuilder.Dot(Visit(expression).AsExpression(), _hqlTreeBuilder.Class()),
                               nodes[0]));
                }

                if (nodes.Count > 1)
                {
                    return(_hqlTreeBuilder.In(
                               _hqlTreeBuilder.Dot(
                                   Visit(expression).AsExpression(),
                                   _hqlTreeBuilder.Class()),
                               _hqlTreeBuilder.ExpressionSubTreeHolder(nodes)));
                }

                if (nodes.Count == 0)
                {
                    const string abstractClassWithNoSubclassExceptionMessageTemplate =
                        @"The class {0} can't be instatiated and does not have mapped subclasses; 
possible solutions:
- don't map the abstract class
- map its subclasses.";

                    throw new NotSupportedException(string.Format(abstractClassWithNoSubclassExceptionMessageTemplate, meta.EntityName));
                }
            }

            return(_hqlTreeBuilder.Equality(
                       _hqlTreeBuilder.Dot(Visit(expression).AsExpression(), _hqlTreeBuilder.Class()),
                       _hqlTreeBuilder.Ident(type.FullName)));
        }
        /// <summary>
        /// Overrides the BuildHql method to add an expression that supports Linq querying of the supported methods.
        /// </summary>
        public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection <Expression> arguments,
                                             HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
        {
            var source   = visitor.Visit(arguments[0]).AsExpression();
            var property = treeBuilder.Ident("Currency");

            return(treeBuilder.Dot(source, property));
        }
예제 #8
0
        public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection <Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
        {
            string memberName;

            if (VisitorUtil.IsDynamicComponentDictionaryGetter(method, targetObject, arguments, visitor.SessionFactory, out memberName))
            {
                return(treeBuilder.Dot(visitor.Visit(targetObject).AsExpression(), treeBuilder.Ident(memberName)));
            }
            return(treeBuilder.Index(visitor.Visit(targetObject).AsExpression(), visitor.Visit(arguments[0]).AsExpression()));
        }
예제 #9
0
            public override HqlTreeNode BuildHql(
                MethodInfo method,
                Expression targetObject,
                ReadOnlyCollection <Expression> arguments,
                HqlTreeBuilder treeBuilder,
                IHqlExpressionVisitor visitor)
            {
                var propertyName = (string)((ConstantExpression)arguments[1]).Value;

                return(treeBuilder.Dot(
                           visitor.Visit(arguments[0]).AsExpression(),
                           treeBuilder.Ident(propertyName)).AsExpression());
            }
예제 #10
0
        public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection <Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
        {
            string trimWhere;

            if (method.Name == "TrimStart")
            {
                trimWhere = "leading";
            }
            else if (method.Name == "TrimEnd")
            {
                trimWhere = "trailing";
            }
            else
            {
                trimWhere = "both";
            }

            string trimChars = "";

            if (method.GetParameters().Length > 0)
            {
                foreach (char c in (char[])((ConstantExpression)arguments[0]).Value)
                {
                    trimChars += c;
                }
            }


            if (trimChars == "")
            {
                return(treeBuilder.MethodCall("trim", treeBuilder.Ident(trimWhere), treeBuilder.Ident("from"), visitor.Visit(targetObject).AsExpression()));
            }
            else
            {
                return(treeBuilder.MethodCall("trim", treeBuilder.Ident(trimWhere), treeBuilder.Constant(trimChars), treeBuilder.Ident("from"), visitor.Visit(targetObject).AsExpression()));
            }
        }
 /// <inheritdoc />
 public HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection <Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
 {
     return(treeBuilder.Dot(visitor.Visit(arguments[0]).AsExpression(), treeBuilder.Ident("Name").AsExpression()));
 }
 public override HqlExpression BuildHql(HqlExpression expression, ReadOnlyCollection <HqlExpression> arguments, HqlTreeBuilder treeBuilder)
 {
     return(treeBuilder.Dot(expression, treeBuilder.Ident(_subProperty)));
 }
예제 #13
0
 public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection <Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
 {
     return(treeBuilder.MethodCall("cast", visitor.Visit(arguments[0]).AsExpression(), treeBuilder.Ident(NHibernateUtil.TimeAsTimeSpan.Name)));
 }