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();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Use this API it you did an aliastobean transform to type TTransform
        /// </summary>
        /// <typeparam name="TTransform"></typeparam>
        /// <param name="queryable"></param>
        /// <param name="startIndex"></param>
        /// <param name="maxRows">A value of Zero means we're not paging</param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        public RetrievedData <TTransform> RetrieveUsingPaging <TTransform>(IQueryOver <T, T> queryable, int startIndex, int maxRows, bool hasOrderBy = false)
            where TTransform : class //, IEntity<idT>
        {
            IEnumerable <TTransform> result;
            int totalCount = 0;
            IFutureValue <int> futureCount = null;

            if (maxRows > 0)
            {
                futureCount = queryable.Clone().Select(Projections.RowCount()).FutureValue <int>();
                result      = queryable.Skip(startIndex * maxRows).Take(maxRows).Future <TTransform>();
            }
            else //get all
            {
                result = queryable.Future <TTransform>();
            }
            var toReturn = result.ToList();

            if (futureCount != null)
            {
                totalCount = futureCount.Value;
            }
            else
            {
                totalCount = toReturn.Count;
            }
            result      = null;
            futureCount = null;
            return(new RetrievedData <TTransform>
            {
                DataBatch = toReturn,
                TotalCount = totalCount
            });
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="theQueryOver"></param>
        /// <param name="startIndex"></param>
        /// <param name="maxRows">A value of Zero means we're not paging</param>
        /// <param name="hasOrderBy"></param>
        /// <returns></returns>
        public RetrievedData <T> RetrieveUsingPaging(IQueryOver <T, T> theQueryOver, int startIndex, int maxRows, bool hasOrderBy = false)
        {
            IEnumerable <T>    result;
            int                totalCount  = 0;
            IFutureValue <int> futureCount = null;

            if (maxRows > 0)
            {
                futureCount = theQueryOver.Clone().Select(Projections.RowCount()).FutureValue <int>();
                result      = theQueryOver.Skip(startIndex * maxRows).Take(maxRows).Future <T>();
            }
            else //get all
            {
                result = theQueryOver.Future <T>();
            }
            var toReturn = result.ToList();

            if (futureCount != null)
            {
                totalCount = futureCount.Value;
            }
            else
            {
                totalCount = toReturn.Count;
            }
            result      = null;
            futureCount = null;
            return(new RetrievedData <T>
            {
                DataBatch = toReturn,
                TotalCount = totalCount
            });
        }
Esempio n. 4
0
 /// <summary>
 /// Creates row count query (with unique identifier)
 /// </summary>
 /// <param name="query"></param>
 /// <returns></returns>
 private IQueryOver <T> ToDistinctRowCount <T>(IQueryOver <T, T> query) where T : EntityBase
 {
     return(query.Clone()
            .Select(Projections.CountDistinct <T>(x => x.Id))
            .ClearOrders()
            .Skip(0)
            .Take(RowSelection.NoValue));
 }
Esempio n. 5
0
        public static PagedList <T> PagedList <T>(this IQueryOver <T> query, int itemsperpage, int?page)
        {
            var howManyPages = (int)Math.Ceiling((decimal)query.Clone().ClearOrders().RowCount() / (decimal)itemsperpage);

            var items = query
                        .Skip(((page ?? 1) - 1) * itemsperpage)
                        .Take(itemsperpage)
                        .List();

            return(new PagedList <T>(page ?? 1, itemsperpage, howManyPages, items));
        }
Esempio n. 6
0
        private IQueryOver <AggregateNodeStatus, AggregateNodeStatus> GetFilterQuery(QueryDescription query, IQueryOver <AggregateNodeStatus, AggregateNodeStatus> aggQuery)
        {
            var newStyle = new NhAggCriteriaVisitor(Helper).GenerateFilterQuery(query.Criteria);
            IQueryOver <AggregateNodeStatus, AggregateNodeStatus> filteredNewStyle = null;

            if (newStyle.SimpleNhCriterion == null && newStyle.Subquery == null)
            {
                // No criteria found
                filteredNewStyle = aggQuery.Clone();
            }
            else
            {
                filteredNewStyle =
                    aggQuery
                    .Clone()
                    .WithSubquery
                    .WhereProperty(x => x.NodeVersion.Id).In(newStyle.Subquery.Select(x => x.NodeVersion.Id));
            }
            return(filteredNewStyle);
        }
        public void CloneIQueryOverWithSubType()
        {
            IQueryOver <Person, Child> expected =
                CreateTestQueryOver <Person>()
                .JoinQueryOver(p => p.Children);

            IQueryOver <Person, Person> actual = expected.Clone();

            ICriteria expectedCriteria = expected.UnderlyingCriteria.GetCriteriaByAlias("this");

            AssertCriteriaAreEqual(expectedCriteria, actual);
        }
Esempio n. 8
0
        public static IPagedList <TResult> Paged <TQuery, TResult>(this IQueryOver <TQuery, TQuery> queryBase, IProjection countQuery, int pageNumber, int?pageSize = null, bool enableCache = true)
            where TQuery : SystemEntity
        {
            var size          = pageSize ?? MrCMSApplication.Get <SiteSettings>().DefaultPageSize;
            var rowCountQuery = queryBase.Clone();

            IEnumerable <TResult> results = queryBase.Skip((pageNumber - 1) * size).Take(size).MakeCacheable(enableCache).Future <TResult>();

            int rowCount = rowCountQuery.Select(countQuery).ClearOrders().MakeCacheable(enableCache).FutureValue <int>().Value;

            return(new StaticPagedList <TResult>(results, pageNumber, size, rowCount));
        }
        public void CloneIQueryOver()
        {
            IQueryOver <Person> expected =
                CreateTestQueryOver <Person>()
                .Where(p => p.Name == "test")
                .Select(p => p.Name);

            IQueryOver <Person> actual = expected.Clone();

            Assert.That(actual, Is.Not.SameAs(expected));
            Assert.That(actual.UnderlyingCriteria, Is.Not.SameAs(expected.UnderlyingCriteria));
            AssertCriteriaAreEqual(expected.UnderlyingCriteria, actual.UnderlyingCriteria);
        }
Esempio n. 10
0
        public IPage <TResult> FindPage <TResult>(IQueryOver <TResult, TResult> queryOver, IPageable pageRequest)
        {
            IQueryOver <TResult, TResult> countQuery = queryOver.Clone().ClearOrders().ToRowCountInt64Query();

            countQuery.Skip(0).Take(int.MaxValue);
            IFutureValue <long> rowCount = countQuery.Select(Projections.RowCountInt64()).FutureValue <long>();

            queryOver.Skip(pageRequest.FirstItem);
            queryOver.Take(pageRequest.PageSize);

            IEnumerable <TResult> enumerable = queryOver.Future <TResult>();

            return(new Page <TResult>(enumerable.ToList(), pageRequest, rowCount.Value));
        }
Esempio n. 11
0
        public Page <TResult> Page(short pNumber, short pSize, SortType pSort, params Expression <Func <TResult, object> >[] pOrderBy)
        {
            var _count = ((IQueryOver <TResult, TResult>)_query.Clone()).Select(Projections.RowCount()).FutureValue <Int32>();

            for (short f = 0; f < pOrderBy.GetLength(0); f++)
            {
                if (pSort == SortType.Ascending)
                {
                    _query = _query.OrderBy(pOrderBy[f]).Asc();
                }
                else
                {
                    _query = _query.OrderBy(pOrderBy[f]).Desc();
                }
            }

            IEnumerable <TResult> _result = _query.Skip(pSize * (pNumber - 1)).Take(pSize).List <TResult>();

            return(new Page <TResult>(pNumber, pSize, _count.Value, _result));
        }
Esempio n. 12
0
        public void TransformQueryOverToRowCount64()
        {
            IQueryOver <Person> expected =
                CreateTestQueryOver <Person>()
                .Where(p => p.Name == "test")
                .JoinQueryOver(p => p.Children)
                .Where((Child c) => c.Age == 5)
                .Select(Projections.RowCountInt64());

            IQueryOver <Person> actual =
                CreateTestQueryOver <Person>()
                .Where(p => p.Name == "test")
                .JoinQueryOver(p => p.Children)
                .Where((Child c) => c.Age == 5)
                .OrderBy(c => c.Age).Asc
                .Skip(20)
                .Take(10);

            expected = expected.Clone();
            actual   = actual.ToRowCountInt64Query();

            AssertCriteriaAreEqual(expected.UnderlyingCriteria, actual);
        }