If you want custom code...
The repository doesn't need to do anything about paging. Basically, if you wanted to get hold of the second page of 10 items from your tasks layer:
Have the controller accept the relevant values (page size, page number) - I'd normally pass these values in the querystring to allow them to be used with an HTTP GET.
The controller requests the data from the tasks layer, passing the page number and size through.
The tasks layer has code like the following:
var firstItem = pageSize * (pageNumber - 1); // Assuming the first page is page 1.
var data = myStuffRepository.FindAll(new MyStuffByWhateverSpecification(parameter));
Because you're using the NHibernate Linq provider the type of the "data" variable is IQueryable<MyStuff>. Nothing will be executed against the database until the first time you try and enumerate the collection. This also means that the
Skip and Take methods actually affect the query that NHibernate eventually executes.
If you want a slightly easier route...
Then the task layer code looks like:
var data = myStuffRepository.FindAll(new MyStuffByWhateverSpecification(parameter)).AsPagination(pageNumber, pageSize);
This can be a bit fiddly if you are using ViewModels, as you may want to map your IPagination<DomainObject> to an IPagination<ViewModel> - this will mean you can use the MvcContrib grid control. You'll find that if you execute AsPagination
against an IQueryable, you'll probably end up with a LazyPagination<DomainObject>. Your mapper can instantiate a new CustomPagination<ViewModel> and fill it with the mapped data.
Hope that makes sense.
On 1 July 2010 17:20, curlyfro <email@example.com>
i've read several s#arp discussions where they want to repository clean. i can create an extension method or extend the linqrepository but then i'll also need to extend my base entities to include a pageIndex and pageCount. personally, i'd like to see
some basic out of box paging.
how would you recommend handling paging?