Here's a helper function which you pass a criteria expression to and it will
paginate it. I use Futures instead of Multicriteria:
public static IList<T> ExecuteWithPagination<T>(ICriteria criteria,
int currentPageIndex, int itemsPerPage, out int itemCount)
{
if (itemsPerPage < 1) { throw new
ArgumentException("itemsPerPage must be greater than or equal to 1.",
"itemsPerPage"); }
if (currentPageIndex < 0) { throw new
ArgumentException("currentPageIndex must be greater than or equal to zero",
"currentPageIndex"); }
var itemCountCrit = CriteriaTransformer.Clone(criteria);
// For the select of the count we want to clear order by clauses
because they are unnecessary and cause exception with aggregates
itemCountCrit.ClearOrders();
var list = criteria
.SetFirstResult(currentPageIndex * itemsPerPage)
.SetMaxResults(itemsPerPage)
.Future<T>();
var resultCount = itemCountCrit
.SetProjection(Projections.RowCount())
.FutureValue<int>();
itemCount = resultCount.Value;
return new List<T>(list);
}
On Mon, May 3, 2010 at 8:24 AM, Bill Barry <[email protected]> wrote:
> Azhar wrote:
>
>> can anyone help me to create a paginated list with filter and sort
>> criteria using CreateMultiCriteria,
>>
>>
> Reminder to everyone: This list is moderated on first posts to stop
> spammers.
>
>
> Azhar: I flagged your first post as spam. Had you not posted this message
> before I got around to clicking on the email it would never have gotten
> through to the moderation page. When you post to any mailing list, expect
> that your first post will be waiting in a queue for someone to read it and
> decide whether or not it should get on the list. So don't ask if someone can
> help you (a common phishing technique), just ask your question.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "NHibernate Contrib - Development Group" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhcdevs%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhcdevs?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"NHibernate Contrib - Development Group" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhcdevs?hl=en.