Question

I'm attempting to filter a GetPaged() result using SubSonic 3.0 but I haven't been able to find a way.
I've tried using the following:

var list = Class.Find(filter);
var paged = new SubSonic.Schema.PagedList<Class>(list, 1, 10);

This doesn't appear to work, I'm getting a cannot convert error and this would go against the reason for paging, as I'd be pulling the entire list from the database.

If anyone has a method to retrieve a filtered paged list using SubSonic 3.0 it would be much appreciated!

Thanks in advance.

Was it helpful?

Solution

In a question regarding subsoinc you should always say if you are using ActiveRecord, LinqTemplates or the SimpleRepository, which makes it easier to find a appropriate example

Suggested you are using ActiveRecord, you can use the linq approach:

int page = 0;
int pageSize = 10;

var query = from c in Class.All()
            orderby c.Name
            select c;

var totalPages = (int)(query.Count() / pageSize) + 1;

var paged = query.Skip(page*pageSize).Take(pageSize);

foreach(var item in paged)
    Console.WriteLine(item.Name);

or with the QueryTool:

var db = new YourDB();
var result = db.Select.From<Class>()
               .Paged(page, pageSize)
               .ExecuteTypedList<Class>();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top