public List <ProductOptionSortingData> Search(ProductOptionSortingSearchQuery searchQuery) { ProductOption productOptionAlias = null; IQueryOver <ProductOption, ProductOption> queryOver = _session.QueryOver(() => productOptionAlias); ProductOptionSortingData sortingDataAlias = null; queryOver.SelectList(builder => builder .Select(() => productOptionAlias.Id).WithAlias(() => sortingDataAlias.Id) .Select(() => productOptionAlias.Name).WithAlias(() => sortingDataAlias.Name) ); return(queryOver.TransformUsing(Transformers.AliasToBean <ProductOptionSortingData>()) .List <ProductOptionSortingData>().ToList()); }
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); }