public static IEnumerable<T> Enumerate<T>(this ICriteria criteria, int pageSize = 1000) { var entityCount = CriteriaTransformer.TransformToRowCount(criteria).UniqueResult<int>(); var pageCount = (int) Math.Ceiling(entityCount/(double) pageSize); criteria = CriteriaTransformer.Clone(criteria).SetMaxResults(pageSize); return Enumerable.Range(0, pageCount) .SelectMany(pageNum => criteria.SetFirstResult(pageNum*pageSize).List<T>()); }NHibernate
No comments:
Post a Comment