private Task <IList <T> > GetResultUsingProjectionAsync(IQueryOver <T, T> query, string[] fields = null, CancellationToken token = default(CancellationToken)) { if (fields == null || fields.Length == 0) { return(query.ListAsync <T>(token)); } var projectionList = Projections.ProjectionList() .Add(Projections.Id(), "Id"); foreach (var prop in fields) { if (prop == "Id") { continue; } projectionList.Add(Projections.Property(prop), prop); } var results = query.Select(projectionList) .TransformUsing(Transformers.AliasToBean <T>()) .ListAsync <T>(token); return(results); }
private int GetCount(IQueryOver <AggregateNodeStatus, AggregateNodeStatus> aggQuery, bool requiresLoadingIds) { if (requiresLoadingIds) { // We can't do a count in the db engine and must load the distinct Ids instead var ids = aggQuery .Select(Projections.Distinct(Projections.Property <AggregateNodeStatus>(x => x.Node.Id))) .Future <Guid>(); return(ids.Distinct().Count()); } int count; if (Helper.SupportsCountDistinct()) { // Set the aggregate to return a count of the distinct NodeIds aggQuery = aggQuery.Select(Projections.CountDistinct <AggregateNodeStatus>(x => x.Node.Id)); count = aggQuery.FutureValue <int>().Value; } else { // SqlCe doesn't support distinct in aggregates, so create a subquery // The ideal subquery for SqlCe would be // select count(*) from (select distinct NodeId ...) // However you can't select from a derived table in NH so we have to do a // select count(*) where exists (select distinct NodeId .. where versionid & statusid match) // We could revert back to the ideal version if we used manual Sql concatenation // Create the distinct NodeId projection aggQuery = aggQuery.Select(Projections.Distinct(Projections.Property <AggregateNodeStatus>(x => x.Node.Id))); // Add some criteria to the inner aggregate query to tie it to the new outer one we'll create for the count AggregateNodeStatus outer = null; aggQuery = aggQuery .Where(x => x.NodeVersion == outer.NodeVersion) .And(x => x.StatusType == outer.StatusType); var outerQuery = Helper.NhSession.QueryOver(() => outer) .Select(Projections.Count <AggregateNodeStatus>(x => x.Node.Id)) .WithSubquery.WhereExists((QueryOver <AggregateNodeStatus>)aggQuery); count = outerQuery.FutureValue <int>().Value; } return(count); }
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); }
/// <summary> /// Conteggio degli elementi restituiti dalla query attualmente utilizzata /// </summary> /// <returns></returns> public override int Count() { IQueryOver <ResolutionKind, ResolutionKind> queryOver = CreateQueryOver(); queryOver = DecorateCriteria(queryOver); queryOver = AttachFilterExpressions(queryOver); return(queryOver.Select(Projections.CountDistinct <ResolutionKind>(resl => resl.Id)) .FutureValue <int>() .Value); }
/// <summary> /// Conteggio elementi /// </summary> public override int Count() { IQueryOver <Desk, Desk> queryOver = CreateQueryOver(); queryOver = DecorateCriteria(queryOver); queryOver = AttachFilterExpressions(queryOver); return(queryOver.Select(Projections.CountDistinct <DeskDocumentEndorsement>(x => x.Id)) .FutureValue <int>() .Value); }
public override int Count() { IQueryOver <PECMailBoxUser, PECMailBoxUser> queryOver = CreateQueryOver(); queryOver = DecorateCriteria(queryOver); queryOver = AttachFilterExpressions(queryOver); return(queryOver.Select(Projections.CountDistinct <PECMailBoxUser>(x => x.Id)) .FutureValue <int>() .Value); }
public override int Count() { IQueryOver <UDSRepository, UDSRepository> queryOver = CreateQueryOver(); queryOver = DecorateCriteria(queryOver); queryOver = AttachFilterExpressions(queryOver); return(queryOver.Select(Projections.CountDistinct <UDSRepository>(u => u.Id)) .FutureValue <int>() .Value); }
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)); }
public IList <Category> GetFascicolableCategoriesByName(string findName) { Category category = null; IQueryOver <CategoryFascicle, CategoryFascicle> query = NHibernateSession.QueryOver <CategoryFascicle>() .JoinAlias(x => x.Category, () => category) .Where(x => x.FascicleType != FascicleType.SubFascicle); if (!string.IsNullOrEmpty(findName)) { query = query.Where(Restrictions.On(() => category.Name).IsLike(findName, MatchMode.Anywhere)); } return(query.Select(Projections.Distinct(Projections.Property <CategoryFascicle>(s => s.Category))) .List <Category>()); }
// TODO: Verificare se è ancora una funzione necessaria protected virtual bool CreateProjections(IQueryOver <T, T> queryOver, Expression <Func <T, object> > projection) { if (SelectProjections == null) { return(false); } try { queryOver.Select(projection); } catch (Exception ex) { throw new DocSuiteException("Errore proiezioni", "Errore nell'impostazione proiezioni", ex); } return(true); }
/// <summary> /// Crea le proiezioni (Proprietà Sorgente - Proprietà Destinazione) da attuare sul criterio. /// </summary> /// <returns>True se esistono proiezioni, False altrimenti</returns> // TODO: Verificare se è ancora una funzione necessaria protected virtual bool CreateProjections(IQueryOver <T, T> queryOver) { if (SelectProjections == null) { return(false); } ProjectionList projList = Projections.ProjectionList(); try { foreach (ParameterExpression property in SelectProjections.Parameters) { projList.Add <T>(Projections.Property(property.Name), SelectProjections); } queryOver.Select(projList); } catch (Exception ex) { throw new DocSuiteException("Errore proiezioni", "Errore nell'impostazione proiezioni", ex); } return(true); }