简体   繁体   English

如何使用ActiveRecord在SubSonic 3.0中筛选GetPaged

[英]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. 我正在尝试使用SubSonic 3.0筛选GetPaged()结果,但我一直找不到方法。
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! 如果任何人都有使用SubSonic 3.0检索筛选的页面列表的方法,将不胜感激!

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 在有关subsoinc的问题中,您应该始终说出您使用的是ActiveRecord,LinqTemplates还是SimpleRepository,这样可以更轻松地找到合适的示例

Suggested you are using ActiveRecord, you can use the linq approach: 建议您使用ActiveRecord,可以使用linq方法:

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: 或使用QueryTool:

var db = new YourDB();
var result = db.Select.From<Class>()
               .Paged(page, pageSize)
               .ExecuteTypedList<Class>();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM