This project is read-only.

Paging

Jul 1, 2010 at 5:20 PM

 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?

Jul 1, 2010 at 5:38 PM
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));
return data.Skip(firstItem).Take(pageSize);

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.
Jon



On 1 July 2010 17:20, curlyfro <notifications@codeplex.com> wrote:

From: curlyfro

 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?

Read the full discussion online.

To add a post to this discussion, reply to this email (whocanhelpme@discussions.codeplex.com)

To start a new discussion for this project, email whocanhelpme@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Jul 1, 2010 at 5:44 PM

ok -- thanks.