开发者

How to filter a GetPaged in SubSonic 3.0 using ActiveRecord

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.


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>();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜