Пример #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
            });
        }
Пример #2
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));
        }
Пример #3
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);
        }
Пример #4
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
            });
        }
 public static IEnumerable <TU> Future <T, TU>(this IQueryOver <T> query, IDatabaseProvider databaseProvider)
 {
     if (databaseProvider.SupportFuture)
     {
         return(query.Future <TU>());
     }
     return(query.List <TU>());
 }
Пример #6
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));
        }
Пример #7
0
        static public PagedResult <DTO> ToPagedResults <DTO, Model>(this IQueryOver <Model, Model> query, PartialRetrievingInfo retrievingInfo, string countPropertyName = null, Func <IEnumerable <Model>, DTO[]> mappingMethod = null, IQueryOver <Model, Model> fetchQuery = null)
        {
            IEnumerable <Model> queryEnumerable = null;

            if (fetchQuery != null)
            {
                fetchQuery.ApplyPaging(retrievingInfo).Future();
            }


            int count = 0;

            if (retrievingInfo.PageSize > PartialRetrievingInfo.AllElementsPageSize)
            {
                IFutureValue <int> rowCountQuery = query.ToRowCountQuery().FutureValue <int>();
                IQueryOver <Model> pagedResults  = query.ApplyPaging(retrievingInfo);

                queryEnumerable = pagedResults.Future();
                count           = rowCountQuery.Value;
            }
            else
            {
                queryEnumerable = query.Future();
                count           = queryEnumerable.Count();
            }

            DTO[] list = null;
            if (mappingMethod == null)
            {
                list = Mapper.Map <IEnumerable <Model>, DTO[]>(queryEnumerable);
            }
            else
            {
                list = mappingMethod(queryEnumerable);
            }
            PagedResult <DTO> res = new PagedResult <DTO>(list, count, retrievingInfo.PageIndex);

            res.RetrievedDateTime = DateTime.UtcNow;
            Log.WriteInfo("Paged result. AllCount:{0},PageIndex:{1},PageSize:{2}", res.AllItemsCount, res.PageIndex, res.Items.Count);
            return(res);
        }
        public static ListaPaginada <object> PaginadoObject <T>(this IQueryOver <T, T> query, int pagina, int tamanhoPagina) where T : class
        {
            IFutureValue <long> count = MontarQueryPaginado(query, pagina, tamanhoPagina);

            return(new ListaPaginada <object>(query.Future <object>(), count.Value, tamanhoPagina));
        }
 public IList <TRoot> List()
 {
     Build();
     return(new List <TRoot>(MainQuery.Future()));
 }