Exemplo n.º 1
0
        public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection <Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
        {
            HqlExpression value        = visitor.Visit(arguments[0]).AsExpression();
            HqlTreeNode   inClauseNode = BuildInClause(arguments, treeBuilder, visitor);

            HqlTreeNode inClause = treeBuilder.In(value, inClauseNode);

            if (method.Name == "NotIn")
            {
                inClause = treeBuilder.BooleanNot((HqlBooleanExpression)inClause);
            }

            return(inClause);
        }
Exemplo n.º 2
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)));
        }
Exemplo n.º 3
0
        public override HqlTreeNode BuildHql(MethodInfo method, System.Linq.Expressions.Expression targetObject, ReadOnlyCollection <System.Linq.Expressions.Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
        {
            var         value = visitor.Visit(arguments[0]).AsExpression();
            HqlTreeNode inClauseNode;

            if (arguments[1] is ConstantExpression)
            {
                inClauseNode = BuildFromArray((Array)((ConstantExpression)arguments[1]).Value, treeBuilder);
            }
            else
            {
                inClauseNode = BuildFromExpression(arguments[1], visitor);
            }

            HqlTreeNode inClause = treeBuilder.In(value, inClauseNode);

            if (method.Name == "NotIn")
            {
                inClause = treeBuilder.BooleanNot((HqlBooleanExpression)inClause);
            }

            return(inClause);
        }
Exemplo n.º 4
0
 public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection <Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
 {
     return(treeBuilder.In(visitor.Visit(arguments[0]).AsExpression(), treeBuilder.Indices(visitor.Visit(targetObject).AsExpression())));
 }