使用 Active Record 进行查找分页
我似乎找不到这个问题的答案,也找不到如何完成我想做的事情的好例子。我确信它已在某处发布或解释,但我无法找到我需要的确切解决方案。
我在 Subsonic 3.0.0.4 中使用 ActiveRecord。 之类的操作时
recordset = VehicleModel.Find(x => x.Model.StartsWith(SearchText));
当我执行诸如返回 VehicleModel 对象的 IList(或更简单地说是记录集) ,这很好,直到我返回太多记录。我也无法订购返回的记录集(我的网格可以很好地做到这一点,但我确信如果我有太多记录,它会太慢)。由于 Find 返回的是 IList,所以我没有太多可以直接针对它运行的东西(我可能会再次忽略一些简单的东西,所以请不要杀我)。
我的问题是有人可以解释如何找到像我上面这样的数据,对其进行排序并获取一页大小为 n 的数据吗?
我在这件事上做错了吗?我已经接近走上正轨了吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设 currentPage 从 0 开始。
如果您的 currentPage 从 1 开始,则其
Skip((currentPage - 1) x PageSize)
this is assuming currentPage starts at 0.
if your currentPage starts at 1, then its
Skip((currentPage - 1) x PageSize)