views:

46

answers:

1

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?

A: 
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)

spaceman
When I type in the . after SearchText)) I don't get Skip as an option and when i compile i get an error (Error 1 'System.Collections.Generic.IList<DB.VehicleModel>' does not contain a definition for 'Skip' and no extension method 'Skip' accepting a first argument of type 'System.Collections.Generic.IList<DB.VehicleModel>' could be found (are you missing a using directive or an assembly reference?). As I mentioned in the initial question Find is returning an IList, maybe the ActiveRecord.tt file i'm using is older or maybe I'm missing something else?
Brian Rizzo
I'm an idiot. I was missing my using System.Linq;Thanks for helping me realize that I need more sleep and less coffee.
Brian Rizzo
looking at the code again now, im pretty sure you can use the subsonic GetPaged method instead.
spaceman