Exemplo n.º 1
0
        static public PagedResult <DTO> ToExPagedResults <DTO, Model>(this IQueryOver <Model, Model> query, PartialRetrievingInfo retrievingInfo, IQueryOver <Model, Model> idQuery, Func <IEnumerable <Model>, DTO[]> mappingMethod = null)
            where Model : FMGlobalObject
        {
            IEnumerable <Model> queryEnumerable = null;
            int count = 0;

            query = query.TransformUsing(Transformers.DistinctRootEntity);
            if (retrievingInfo.PageSize > PartialRetrievingInfo.AllElementsPageSize)
            {
                ICriteria countCriteria = CriteriaTransformer.Clone(idQuery.RootCriteria);
                countCriteria.SetProjection(Projections.CountDistinct("GlobalId"));
                IFutureValue <int> rowCountQuery = countCriteria.FutureValue <int>();

                idQuery = (QueryOver <Model, Model>)idQuery.ApplyPaging(retrievingInfo);
                var ids = idQuery.Select(Projections.Distinct(Projections.Property("GlobalId"))).Future <Guid>();
                count = rowCountQuery.Value;

                query           = query.WhereRestrictionOn(x => x.GlobalId).IsIn(ids.ToList());
                queryEnumerable = query.List();
            }
            else
            {
                var ids = idQuery.Select(Projections.Distinct(Projections.Property("GlobalId"))).Future <Guid>();
                query           = query.WhereRestrictionOn(x => x.GlobalId).IsIn(ids.ToList());
                queryEnumerable = query.List();
                count           = queryEnumerable.Count();
            }

            DTO[] list = null;
            if (mappingMethod == null)
            {
                var temp = queryEnumerable.ToList();
                list = Mapper.Map <IEnumerable <Model>, DTO[]>(temp);
            }
            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);
        }
Exemplo n.º 2
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);
        }