/// <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)); }
public long CountLong <T>(params Expression <Func <T, bool> >[] where) where T : class { IQueryOver <T, T> query = session.QueryOver <T>(); foreach (var w in where) { query = query.And(w); } return(query.RowCountInt64()); }
/// <summary> /// 按Query条件查询并返回支持分页的对象列表 /// </summary> /// <param name="query">查询条件</param> /// <param name="pagingInfo">分页信息</param> /// <param name="orderBy">排序字段信息</param> /// <returns>支持翻页的对象列表</returns> public virtual IPagedList <T> GetObjectPagedList(IQueryOver <T, T> query, IPagingInfo pagingInfo, OrderField orderBy) { bool needPaging = pagingInfo != null && pagingInfo.IsLegal; if (needPaging) { if (pagingInfo.DoCount) { pagingInfo.RecordCount = query.RowCountInt64(); } query.Skip((pagingInfo.CurrentPage - 1) * pagingInfo.PageSize).Take(pagingInfo.PageSize); } query.RootCriteria.AddOrder(new Order(orderBy.PropertyName, orderBy.Ascending)); IList <T> list = query.List <T>(); return(needPaging ? list.ToPagedList(pagingInfo.CurrentPage, pagingInfo.PageSize, (int)pagingInfo.RecordCount) : list.ToPagedList(1, list.Count)); }
public void RowCount() { SetupPagingData(); using (ISession s = OpenSession()) { IQueryOver <Person> query = s.QueryOver <Person>() .JoinQueryOver(p => p.Children) .OrderBy(c => c.Age).Desc .Skip(2) .Take(1); IList <Person> results = query.List(); int rowCount = query.RowCount(); object bigRowCount = query.RowCountInt64(); Assert.That(results.Count, Is.EqualTo(1)); Assert.That(results[0].Name, Is.EqualTo("Name 3")); Assert.That(rowCount, Is.EqualTo(4)); Assert.That(bigRowCount, Is.TypeOf <long>()); Assert.That(bigRowCount, Is.EqualTo(4)); } }
public long RowCountInt64() { return(MainQuery.RowCountInt64()); }