Question

I can't seem to find an answer to this question or a good example of how to accomplish what I am trying to do. I'm sure it's been posted or explained somewhere, but I am having trouble finding the exact solution I need.

I am using ActiveRecord in Subsonic 3.0.0.4. When I do something like

recordset = VehicleModel.Find(x => x.Model.StartsWith(SearchText));

I get back an IList of VehicleModel objects (or more simply a recordset), this is fine until I return too many records. I also cannot order the returned set of records (my grid will do this fine, but i'm sure it will be too slow if i have too many records). Being that Find is returning an IList there isn't much that I can run directly against this (again I may be overlooking something simple so please don't kill me).

My question is can someone explain how to find data like i am above, sort it and get a page of data where a page is of size n?

Am I going about this wrong? Am I even close to being on the right track?

Was it helpful?

Solution

int currentPage = x
int pageSize = n
recordset = VehicleModel.Find(x => x.Model.StartsWith(SearchText)).Skip(currentPage x PageSize).Take(PageSize);

this is assuming currentPage starts at 0.
if your currentPage starts at 1, then its Skip((currentPage - 1) x PageSize)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top