コード例 #1
0
        private void BuildWithSubquery()
        {
            var criteria       = (CriteriaImpl)MainQuery.UnderlyingCriteria;
            var session        = (SessionImpl)criteria.Session;
            var metaData       = session.SessionFactory.GetClassMetadata(typeof(TRoot));
            var idName         = metaData.IdentifierPropertyName; //TODO: multiple props
            var pe             = Expression.Parameter(typeof(TRoot));
            var idExprBody     = Expression.Property(pe, typeof(TRoot).GetProperty(idName));
            var expr           = Expression.Lambda(idExprBody, pe);
            var mainCloned     = MainQuery.Clone();
            var projectionList = new List <IProjection>();

            projectionList.Add(ExpressionProcessor.FindMemberProjection(expr.Body).AsProjection());
            mainCloned.UnderlyingCriteria.SetProjection(projectionList.ToArray());
            var tree = new QueryRelationTree();

            foreach (var pathExpr in Includes)
            {
                tree.AddNode(pathExpr);
            }
            foreach (var pair in tree.DeepFirstSearch())
            {
                var query = session.QueryOver <TRoot>();
                //Add a SubQuery
                query.And(Subqueries.PropertyIn(idName, ((QueryOver <TRoot, TRoot>)mainCloned).DetachedCriteria));
                CopyCriteriaValues(criteria, query);
                FillSubQuery(pair.Value, query, criteria);
                query.Future();
            }
        }
コード例 #2
0
        private void BuildWithoutSubQuery()
        {
            var criteria = (CriteriaImpl)MainQuery.UnderlyingCriteria;
            var tree     = new QueryRelationTree();

            foreach (var pathExpr in Includes)
            {
                tree.AddNode(pathExpr);
            }
            foreach (var pair in tree.DeepFirstSearch())
            {
                var query = MainQuery.Clone();
                FillSubQuery(pair.Value, query, criteria);
                query.Future();
            }
        }