Exemplo n.º 1
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
            });
        }
Exemplo n.º 2
0
 public static IQueryOver <T> Paginado <T>(
     this IQueryOver <T, T> query, int page, int itemsPerPage)
 {
     return(query
            .Skip(page.PaginateSkip(itemsPerPage))
            .Take(itemsPerPage));
 }
Exemplo n.º 3
0
        public static IList <T> GetQueryOver <T>(IQueryOver <T, T> query, List <SortOrder <T> > expressionOrder, Pagination pagination)
        {
            if (expressionOrder != null)
            {
                for (int i = 0; i < expressionOrder.Count; i++)
                {
                    var model = expressionOrder[i];
                    IQueryOverOrderBuilder <T, T> sort;
                    if (i > 0)
                    {
                        sort = query.ThenBy(model.value);
                    }
                    else
                    {
                        sort = query.OrderBy(model.value);
                    }
                    if (model.searchType == EnumBase.OrderType.Asc)
                    {
                        query = sort.Asc;
                    }
                    else
                    {
                        query = sort.Desc;
                    }
                }
            }
            if (pagination != null)
            {
                query.Skip((pagination.pageIndex - 1) * pagination.pageSize);
                query.Take(pagination.pageSize);
            }
            var list = query.List <T>();

            return(list);
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Versuch über ein Detached Criteria die Where-Klauseln zu verarbeiten, damit es mit dem Order nicht zu
        ///     komplikationen kommt.
        /// </summary>
        protected virtual IPage <T> Find(IPageable pageable, Action <IQueryOver <T, T> > criteriaBuilder, Action <IQueryOver <T, T> > ordersBuilder = null)
        {
            Require.NotNull(pageable, "pageable");
            Require.NotNull(criteriaBuilder, "criteriaBuilder");

            HibernateDelegate <IPage <T> > finder = delegate(ISession session) {
                IQueryOver <T, T> query = session.QueryOver <T>();
                criteriaBuilder(query);
                if (ordersBuilder != null)
                {
                    ordersBuilder(query);
                }

                IQueryOver <T, T> countQuery = session.QueryOver <T>();
                criteriaBuilder(countQuery);

                query.Skip(pageable.FirstItem);
                query.Take(pageable.PageSize);

                long            futureTotalCount = countQuery.RowCountInt64();
                IEnumerable <T> futureElements   = query.Future <T>();
                Page <T>        page             = new Page <T>(futureElements.ToList(), pageable, futureTotalCount);
                return(page);
            };

            return(HibernateTemplate.Execute(finder));
        }
Exemplo n.º 5
0
        public static PagedResultSet <T> ToPagedSet <T>(this IQueryOver <T, T> query, ListOptions listOptions)
        {
            var count   = query.ToRowCountQuery().FutureValue <int>();
            var results = query.Skip(listOptions.PageSize * listOptions.Page).Take(listOptions.PageSize).Future();

            return(new PagedResultSet <T>(results, count.Value));
        }
Exemplo n.º 6
0
        public override Response Handle(PagedSearchRequest <TDto> request)
        {
            var response = CreateTypedResponse();

            var keyword = request.Keyword + "%";
            IQueryOver <TEntity> query = null;
            var entityQuery            = Session.QueryOver <TEntity>()
                                         .Where(WhereExpress(keyword));
            var organizationExpression = GetOrganization();

            if (organizationExpression != null)
            {
                query = entityQuery.JoinQueryOver(organizationExpression)
                        .Where(o => o.Key == UserContext.OrganizationKey);
            }
            else
            {
                query = entityQuery;
            }
            query = query.Skip(request.Page * request.PageSize)
                    .Take(request.PageSize);
            var result = query.Future <TEntity>() ?? Enumerable.Empty <TEntity> ();

            response.TotalCount = query.ToRowCountQuery().FutureValue <int>().Value;
            response.Results    = Mapper.Map <IEnumerable <TEntity>, IEnumerable <TDto> > (result.ToList());
            return(response);
        }
Exemplo n.º 7
0
        private static bool ApplySkipOrTakeInDbIfPossible(QueryDescription query, ref IQueryOver <AggregateNodeStatus, AggregateNodeStatus> filteredAggQuery)
        {
            bool modified = false;

            if (CanApplySortOrderInDb(query) != ApplySortOrderInDb.CannotApplyAll)
            {
                foreach (var filter in query.ResultFilters)
                {
                    switch (filter.ResultFilterType)
                    {
                    case ResultFilterType.Skip:
                        filteredAggQuery =
                            (IQueryOver <AggregateNodeStatus, AggregateNodeStatus>)
                            filteredAggQuery.Skip(filter.SkipCount).Take(9999);
                        modified = true;
                        break;

                    case ResultFilterType.Take:
                        filteredAggQuery =
                            (IQueryOver <AggregateNodeStatus, AggregateNodeStatus>)
                            filteredAggQuery.Take(filter.TakeCount);
                        modified = true;
                        break;
                    }
                }
            }
            return(modified);
        }
Exemplo n.º 8
0
        public IList <Enrollee> GetallenrolleeRange(out int totalRecord, int start, int lenght)
        {
            IQueryOver <Enrollee, Enrollee> query = _session.QueryOver <Enrollee>().Where(x => x.IsDeleted == false && x.Isexpundged == false);

            totalRecord = query.RowCount();
            return(query.Skip(start).Take(lenght).List());
        }
        public static IList <T> GetPagedResult <T>(this IQueryOver <T> query, PagedRequestDescription description)
        {
            query.Sort(description.JtSortingColumn, description.JtAscending);
            var entities = query.Skip(description.JtStartIndex).Take(description.JtPageSize).List <T>();

            return(entities);
        }
Exemplo n.º 10
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
            });
        }
Exemplo n.º 11
0
 /// <summary>
 /// Esegue la paginazione dei dati.
 /// </summary>
 /// <param name="queryOver"></param>
 /// <returns></returns>
 protected virtual IQueryOver <T, T> ExecutePaging(IQueryOver <T, T> queryOver)
 {
     if (EnablePaging)
     {
         queryOver.Skip(PageIndex);
         queryOver.Take(PageSize);
     }
     return(queryOver);
 }
Exemplo n.º 12
0
        public PagedObject <T> Paginate(IQueryOver <T> query, int pageSize, int pageNumber)
        {
            this.rowCount    = query.RowCount();
            this.pageCount   = Math.Ceiling(this.rowCount / pageSize);
            this.pageSize    = pageSize;
            this.ResultQuery = query.Skip((pageNumber - 1) * pageSize).Take(pageSize);

            return(this);
        }
Exemplo n.º 13
0
        public static IQueryOver <TRoot> AddSkip <TRoot>(this IQueryOver <TRoot> queryOver, int?skip)
        {
            if (skip.HasValue && skip.Value > 0)
            {
                return(queryOver.Skip(skip.Value));
            }

            return(queryOver);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Paging extensions of <see cref="IQueryOver{TRoot}"/>
        /// </summary>
        /// <typeparam name="T">{T}</typeparam>
        /// <param name="queryOver"><see cref="IQueryOver{TRoot}"/></param>
        /// <param name="currentPage">Current page</param>
        /// <param name="pageSize">Page size</param>
        /// <param name="records">Records</param>
        /// <returns><see cref="IPaging{T}"/></returns>
        public static IPaging <T> Paging <T>(this IQueryOver <T> queryOver, int currentPage, int pageSize, long?records)
        {
            queryOver.Skip(currentPage * pageSize);
            queryOver.Take(pageSize);

            return(records.HasValue
                       ? queryOver.List <T>().Paging(currentPage, pageSize, records.Value)
                       : queryOver.List <T>().Paging(currentPage, pageSize));
        }
Exemplo n.º 15
0
        private static IFutureValue <long> MontarQueryPaginado <T>(IQueryOver <T, T> query, int pagina, int tamanhoPagina) where T : class
        {
            IFutureValue <long> count = query.ToRowCountInt64Query().FutureValue <long>();

            if (pagina > 0 && tamanhoPagina > 0)
            {
                query.Skip((pagina - 1) * tamanhoPagina).Take(tamanhoPagina);
            }

            return(count);
        }
Exemplo n.º 16
0
        public static IPagedList <TResult> Paged <TResult>(this IQueryOver <TResult, TResult> queryBase, int pageNumber,
                                                           int?pageSize = null)
            where TResult : SystemEntity
        {
            int size = pageSize ?? MrCMSApplication.Get <SiteSettings>().DefaultPageSize;
            IEnumerable <TResult> results = queryBase.Skip((pageNumber - 1) * size).Take(size).Cacheable().List();

            int rowCount = queryBase.Cacheable().RowCount();

            return(new StaticPagedList <TResult>(results, pageNumber, size, rowCount));
        }
Exemplo n.º 17
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));
        }
Exemplo n.º 18
0
        public IList <Supervise> QuerySupervise(Paging info, out int total)
        {
            using ISession session = DbFactory.OpenSession();
            IQueryOver <Supervise> queries = session.QueryOver <Supervise>();

            SetQueryArg(queries.RootCriteria, info.Get());
            total = queries.RowCount();
            return(queries
                   .Skip((info.Page - 1) * info.Limit)
                   .Take(info.Limit)
                   .List());
        }
Exemplo n.º 19
0
        public IList <WorkflowStructure> Query(int pageIndex, int pageSize, out int total, Dictionary <string, string> queryArg)
        {
            using ISession session = DbFactory.OpenSession();
            IQueryOver <WorkflowStructure> queries = session.QueryOver <WorkflowStructure>();

            SetQueryArg(queries.RootCriteria, queryArg);
            total = queries.RowCount();
            return(queries
                   .Skip((pageIndex - 1) * pageSize)
                   .Take(pageSize)
                   .List());
        }
Exemplo n.º 20
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));
        }
Exemplo n.º 21
0
        public static IQueryOver <TPersistenceModel> ApplyPaging <TPersistenceModel>(
            this IQueryOver <TPersistenceModel> queryOver, int currentPageNumber, int pageSize)
        {
            if (currentPageNumber < 1)
            {
                throw new ArgumentOutOfRangeException("currentPageNumber", "Page number can't be less than 1");
            }

            var query = queryOver.Skip((currentPageNumber - 1) * pageSize)
                        .Take(pageSize);

            return(query);
        }
Exemplo n.º 22
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));
        }
Exemplo n.º 23
0
        public static IQueryOver <T> Paged <T>(this IQueryOver <T, T> query, int first, int length)
        {
            if (first > 0)
            {
                query.Skip(first);
            }

            if (length > 0)
            {
                query.Take(length);
            }

            return(query);
        }
Exemplo n.º 24
0
        public IList <ServiceTariff> QueryAllServiceTariff(out int totalRecord, out int totalcountinresult, string search, int start, int lenght, string sortColumn, int groupid, string sortOrder, string scrProvider, string scrUsers, int otherFilters)
        {
            IQueryOver <ServiceTariff, ServiceTariff> query = _session.QueryOver <ServiceTariff>().Where(x => x.IsDeleted == false && x.GroupId == groupid);

            if (!string.IsNullOrEmpty(search))
            {
                search = "%" + search + "%";
                query.Where(Restrictions.On <ServiceTariff>(x => x.Name).IsInsensitiveLike(search));
            }

            //return normal list.
            totalRecord        = query.RowCount();
            totalcountinresult = totalRecord;
            return(query.Skip(start).Take(lenght).List());
        }
Exemplo n.º 25
0
        public static IQueryOver <TEntity, TEntity> SkipTake <TEntity>(
            this IQueryOver <TEntity, TEntity> query, int skip, int take)
        {
            if (skip > 0)
            {
                query.Skip(skip);
            }

            if (skip > 0)
            {
                query.Take(take);
            }

            return(query);
        }
        public static IQueryOver <People, People> Pagination(this IQueryOver <People, People> model, string skip, string top)
        {
            var skipAsInteger = string.IsNullOrEmpty(skip) ? 0 : int.Parse(skip);
            var topAsInteger  = string.IsNullOrEmpty(top) ? 0 : int.Parse(top);

            if (skipAsInteger > 0)
            {
                model.Skip(skipAsInteger);
            }

            if (topAsInteger > 0)
            {
                model.Take(topAsInteger);
            }

            return(model);
        }
Exemplo n.º 27
0
        /// <summary>
        /// 按Query条件查询并返回支持分页的对象列表
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <param name="pagingInfo">分页信息</param>
        /// <param name="orderBy">排序字段信息</param>
        /// <returns>支持翻页的对象列表</returns>
        public virtual IPagedList <T> GetObjectPagedList(IQueryOver <T, T> query, IPagingInfo pagingInfo, OrderField orderBy)
        {
            bool needPaging = pagingInfo != null && pagingInfo.IsLegal;

            if (needPaging)
            {
                if (pagingInfo.DoCount)
                {
                    pagingInfo.RecordCount = query.RowCountInt64();
                }
                query.Skip((pagingInfo.CurrentPage - 1) * pagingInfo.PageSize).Take(pagingInfo.PageSize);
            }

            query.RootCriteria.AddOrder(new Order(orderBy.PropertyName, orderBy.Ascending));
            IList <T> list = query.List <T>();

            return(needPaging ? list.ToPagedList(pagingInfo.CurrentPage, pagingInfo.PageSize, (int)pagingInfo.RecordCount) : list.ToPagedList(1, list.Count));
        }
Exemplo n.º 28
0
        /// <summary>
        /// NHibernate query state
        /// </summary>
        /// <param name="queryOver"></param>
        /// <param name="skip"></param>
        /// <param name="pageSize"></param>
        public NhCoreQueryState(IQueryOver <T> queryOver, int skip, int pageSize)
        {
            if (queryOver == null)
            {
                throw new ArgumentNullException(nameof(queryOver));
            }

            if (skip < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(skip), $"{nameof(skip)} can not be less than zero");
            }

            if (pageSize < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(pageSize), $"{nameof(pageSize)} can not be less than zero");
            }

            _mLazyChloeQueryMembers = new Lazy <IFutureEnumerable <T> >(() => queryOver.Skip(skip).Take(pageSize).Future());
        }
Exemplo n.º 29
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));
        }
Exemplo n.º 30
0
        public Stream writeEntitiesBatched <T>(IQueryOver <T> query, Func <IList <T>, IList <Feature> > action, string fileName, DbaseFileHeader header = null)
        {
            int i = 0;

            query.CacheMode(CacheMode.Ignore);
            IEnumerable <Feature> features = new List <Feature>();
            IList <T>             batch;

            do
            {
                batch = query.Skip(this.batchSize * i).Take(batchSize).List();
                //batch = query.List();
                features = features.Concat(action.Invoke(batch));
                i++;
            } while (batch.Any());
            if (header != null)
            {
                header.NumRecords = features.Count();
            }
            return(shpShxSerializeService.WriteShape(features.ToList(), fileName, header));
        }