Paging with Find using Active Record
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 Subsoni开发者_运维百科c 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?
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)
精彩评论