public FutureQueryOf(DetachedCriteria detachedCriteria, int firstResult, int maxResults) : this(detachedCriteria .SetFirstResult(firstResult) .SetMaxResults(maxResults), FutureQueryOptions.WithTotalCount) { }
public IPagedList <Album> GetAlbums(ILoadOptions options) { IPagedList <Album> result = new PagedList <Album>(); if (options == null) { return(result); } if (options.MaxResults <= 0) { return(result); } ISession session = SessionFactory.GetSession(); try { DetachedCriteria countCriteria = GetAlbumsImpl(options); DetachedCriteria listCriteria = GetAlbumsImpl(options); countCriteria.SetProjection(Projections.RowCount()); countCriteria.ClearOrders(); listCriteria. SetFirstResult(options.FirstResult). SetMaxResults(options.MaxResults); IMultiCriteria multiCriteria = session.CreateMultiCriteria(); multiCriteria.Add(countCriteria); multiCriteria.Add(listCriteria); IList queryResult = multiCriteria.List(); result.TotalItems = (int)((IList)queryResult[0])[0]; IList recordsList = (IList)queryResult[1]; EntityConverter entityConverter = new EntityConverter(); foreach (var e in recordsList) { AlbumEntity dataEntity = e as AlbumEntity; Album businessEntity = entityConverter.FromDataEntity(dataEntity, AlbumConvertOptions.Small); result.Add(businessEntity); } } catch (Exception ex) { Logger.Write(ex); } finally { session.Close(); } return(result); }
public IEnumerable <T> GetByCrit(DetachedCriteria query, int pageIndex, int pageSize, out int count, string sortFieldName, SortDirection sortDirection) { if (pageSize > 0) { query.SetFirstResult(pageIndex * pageSize) .SetMaxResults(pageSize)//Rizwan:24-Jun-2011 Commented this line ignore as next line contains same thing as well .SetMaxResults(pageSize); } query.AddOrder(new Order(sortFieldName, sortDirection == SortDirection.Ascending ? true : false)); IList <T> result = query.GetExecutableCriteria(this._session).List <T>(); //count = result.Count;//Rizwan:24-JUN-2011 var rowCount = query.SetFirstResult(0).GetExecutableCriteria(this._session).SetProjection(Projections.RowCount()).FutureValue <Int32>(); count = rowCount.Value; return(result); //} }
private static void SetPagination(DetachedCriteria criteria, int pageSize, int pageNumber) { if (criteria == null) { throw new ArgumentNullException("criteria"); } criteria.SetFirstResult(pageSize * (pageNumber < 1 ? 0 : pageNumber - 1)).SetMaxResults(pageSize); }
private static void ResetPagination(DetachedCriteria criteria) { if (criteria == null) { throw new ArgumentNullException("criteria"); } criteria.SetFirstResult(default(int)).SetMaxResults(RowSelection.NoValue); }
protected DetachedCriteria Limit(DetachedCriteria criteria, int start, int max) { if (start >= 1) { criteria.SetFirstResult(start); } if (max >= 0) { criteria.SetMaxResults(max); } return(criteria); }
/// <summary> /// Current Criteria의 Paging 설정을 수행한다. /// </summary> /// <param name="firstResult">결과 Set의 첫번째 인덱스</param> /// <param name="maxResults">결과 Set의 최대 레코드 수 (0 이하이면 설정하지 않는다.)</param> /// <returns>Current instance of CriteriaBatch</returns> public CriteriaBatch Paging(int firstResult, int maxResults) { if (firstResult >= 0) { _currentCriteria.SetFirstResult(firstResult); } if (maxResults > 0) { _currentCriteria.SetMaxResults(maxResults); } return(this); }
//public IEnumerable<T> Get(IQuery query, int baseIndex, short pageSize, out int count, string sortFieldName, SortDirection sortDirection) //{ // //if pageSize>0 then do paging, otherwise no paging and all records will be displayed // if (pageSize > 0) // query.SetFirstResult(baseIndex) // .SetMaxResults(pageSize)//Rizwan:24-Jun-2011 Commented this line ignore as next line contains same thing as well // .SetMaxResults(pageSize); // // query.AddOrder(new Order(sortFieldName, sortDirection == SortDirection.Ascending ? true : false)); // IList<T> result = query.List<T>(); // //count = result.Count;//Rizwan:24-JUN-2011 // var rowCount = query.SetFirstResult(0).List().Count; // count = rowCount; // return result; // //} //} public IEnumerable <T> Get(DetachedCriteria query, int pageIndex, int pageSize, out int count, string sortFieldName, SortDirection sortDirection) { /* * if ((!string.IsNullOrEmpty(sortFieldName))&& sortFieldName != "LeaveTypeId") * { * query.SetFirstResult(pageIndex * pageSize) * .SetMaxResults(pageSize)//Rizwan:24-Jun-2011 Commented this line ignore as next line contains same thing as well * .SetMaxResults(pageSize) * .AddOrder(new Order(sortFieldName, sortDirection == SortDirection.Ascending)); * * IList<T> result = query.GetExecutableCriteria(this._session).List<T>(); * //count = result.Count;//Rizwan:24-JUN-2011 * var rowCount = query.SetFirstResult(0).GetExecutableCriteria(this._session).SetProjection(Projections.RowCount()).FutureValue<Int32>(); * count = rowCount.Value; * return result; * * } * else * { */ //if pageSize>0 then do paging, otherwise no paging and all records will be displayed if (pageSize > 0) { query.SetFirstResult(pageIndex * pageSize) .SetMaxResults(pageSize)//Rizwan:24-Jun-2011 Commented this line ignore as next line contains same thing as well .SetMaxResults(pageSize); } //query.AddOrder(new Order(sortFieldName, sortDirection == SortDirection.Ascending ? true : false)); IList <T> result = query.GetExecutableCriteria(this._session).List <T>(); //count = result.Count;//Rizwan:24-JUN-2011 var rowCount = query.SetFirstResult(0).GetExecutableCriteria(this._session).SetProjection(Projections.RowCount()).FutureValue <Int32>(); count = rowCount.Value; return(result); //} }
/// <summary> /// Adds paging to the DetachedCriteria based on the given parameters. /// </summary> /// <param name="criteria"></param> /// <param name="pageSize"></param> /// <param name="pageNumber"></param> /// <returns></returns> public static DetachedCriteria ApplyPaging(this DetachedCriteria criteria, int?pageSize, int?pageNumber) { if (pageSize.HasValue) { criteria.SetMaxResults(pageSize.Value); } if (pageNumber.HasValue) { if (!pageSize.HasValue) { throw new ArgumentException("Unable to determine the object to return for the given page number when the pagesize is unknown."); } criteria.SetFirstResult(pageSize.Value * (pageNumber.Value - 1)); } return(criteria); }
private IList <RegistrationInformation> AcceptPaginator(DetachedCriteria criteria, ISession session) { var countSubquery = CriteriaTransformer.TransformToRowCount(criteria); _lastRowsCount = countSubquery.GetExecutableCriteria(session).UniqueResult <int>(); if (CurrentPage > 0) { criteria.SetFirstResult(CurrentPage * PageSize); } criteria.SetMaxResults(PageSize); ApplySort(criteria); return(criteria.GetExecutableCriteria(session).ToList <RegistrationInformation>().ToList()); }
private IList <DocumentLog> AcceptPaginator(ISession session, DetachedCriteria criteria, bool forExport = false) { var countQuery = CriteriaTransformer.TransformToRowCount(criteria); if (OnlyNoParsed && !forExport) { if (CurrentPage > 0) { criteria.SetFirstResult(CurrentPage * PageSize); } criteria.SetMaxResults(PageSize); } RowsCount = countQuery.GetExecutableCriteria(session).UniqueResult <int>(); return(criteria.GetExecutableCriteria(session).ToList <DocumentLog>()); }
/// <summary> /// selects a certain amount of entitys /// matching a given criteria. /// Should be used if a lot of data is expected!! /// </summary> /// <typeparam name="T"></typeparam> /// <param name="criteria"></param> /// <param name="firstResult">the index of the first result</param> /// <param name="numberOfResults">how many results do you want to have</param> /// <param name="orders">the order in which it should be selected</param> /// <returns></returns> public IEnumerable <T> SelectCertainNumberWhere <T>(DetachedCriteria criteria, int firstResult, int numberOfResults, params Order[] orders) where T : IEntity { try { criteria.SetFirstResult(firstResult).SetMaxResults(numberOfResults); return(SelectManyWhere <T>(criteria, orders)); } catch (DatabaseException dex) { this.setError(); throw (dex); } catch (Exception ex) { this.setError(); throw (new DatabaseException(ex, "Different Error in selecting")); } }
/// <summary> /// Retunrs the First result matching the given /// criteria or a default entity if there is no result /// thorws an exception if an error occurs. /// Should be used if a lot of data is expected!! /// </summary> /// <typeparam name="T"></typeparam> /// <param name="criteria"></param> /// <returns></returns> public T SelectFirstOfMany <T>(DetachedCriteria criteria) where T : IEntity { try { var results = criteria.SetFirstResult(0).SetMaxResults(1) .GetExecutableCriteria(session).List <T>(); return((results.Count > 0) ? results[0] : default(T)); } catch (DatabaseException dex) { this.setError(); throw (dex); } catch (Exception ex) { this.setError(); throw (new DatabaseException(ex, "Could not select first entity!")); } }
/// <summary> /// </summary> /// <param name="pageIndex"></param> /// <param name="pageSize"></param> /// <param name="type"></param> /// <param name="total"></param> /// <returns></returns> public IList <News> GetNews(int pageIndex, int pageSize, NewsType type, out int total) { if (pageSize <= 0) { throw new ArgumentOutOfRangeException("pageSize", Resources.PageSize_should_greater_than_zero); } if (pageIndex < 0) { throw new ArgumentOutOfRangeException("pageIndex", Resources.PageIndex_should_greater_than_zero_); } total = CountMessage(type); DetachedCriteria cri = CreateDetachedCriteria() .Add(Restrictions.Eq(TypeProperty, type)) .AddOrder(Order.Desc(CreateTimeProperty)); cri.SetFirstResult(pageIndex * pageSize).SetMaxResults(pageSize); return(cri.GetExecutableCriteria(CurrentSession).List <News>()); }
public IList <User> Search(UserSearch userSearch, int pageIndex, int pageSize, out int total, params SortTarget[] sortTargets) { DetachedCriteria result = QuickSearch(userSearch); total = result .SetProjection(Projections.RowCount()) .GetExecutableCriteria(CurrentSession).UniqueResult <int>(); result = QuickSearch(userSearch); if (sortTargets != null && sortTargets.Length != 0) { foreach (SortTarget a in sortTargets) { result.AddOrder(a.Tag == SortTag.Asc ? Order.Asc(Projections.Property(a.Property)) : Order.Desc(Projections.Property(a.Property))); } } return (result.SetFirstResult(pageIndex * pageSize) .SetMaxResults(pageSize) .GetExecutableCriteria(CurrentSession) .List <User>()); }
public NHibernateDynamicQueryGenerator <EntityType> SetFirstResult(int firstResult) { query.SetFirstResult(firstResult); return(this); }
public ICriteria SetFirstResult(int firstResult) { return(detachedCriteria.SetFirstResult(firstResult).Adapt(session)); }
public CriteriaBatch Paging(int firstResult, int maxResults) { currentCriteria.SetFirstResult(firstResult); currentCriteria.SetMaxResults(maxResults); return(this); }
/// <summary> /// Builds a <see cref="DetachedCriteria" /> from the given <see cref="IMorphableFlowQuery" /> query. /// </summary> /// <param name="query"> /// The query from which to build a <see cref="ICriteria" />. /// </param> /// <typeparam name="TSource"> /// The <see cref="System.Type" /> of the underlying entity for the given query. /// </typeparam> /// <returns> /// The built <see cref="DetachedCriteria" />. /// </returns> public virtual DetachedCriteria Build <TSource>(IMorphableFlowQuery query) { if (query == null) { throw new ArgumentNullException("query"); } DetachedCriteria criteria = DetachedCriteria.For <TSource>(query.Alias); foreach (Join join in query.Joins) { criteria.CreateAlias(join.Property, join.Alias, join.JoinType, join.WithClause); } foreach (ICriterion criterion in query.Criterions) { criteria.Add(criterion); } foreach (Lock queryLock in query.Locks) { if (queryLock.Alias == null) { criteria.SetLockMode(queryLock.LockMode); } else { criteria.SetLockMode(queryLock.Alias, queryLock.LockMode); } } bool skips = query.ResultsToSkip.HasValue && query.ResultsToSkip.Value > 0; if (skips) { criteria.SetFirstResult(query.ResultsToSkip.Value); } bool takes = query.ResultsToTake.HasValue && query.ResultsToTake.Value > 0; if (takes) { criteria.SetMaxResults(query.ResultsToTake.Value); } if (query.IsCacheable) { criteria.SetCacheable(true); if (query.CacheMode.HasValue) { criteria.SetCacheMode(query.CacheMode.Value); } if (!string.IsNullOrEmpty(query.CacheRegion)) { criteria.SetCacheRegion(query.CacheRegion); } } criteria .SetProjection ( GetProjection(query) ); if (query.ResultTransformer != null) { criteria.SetResultTransformer(query.ResultTransformer); } if (query.Orders.Count > 0 && (skips || takes)) { foreach (OrderByStatement statement in query.Orders) { if (statement.IsBasedOnSource) { criteria.AddOrder(statement.Order); } } } return(criteria); }