如何使用 NHibernate 进行分页? [英] How can you do paging with NHibernate?

查看:31
本文介绍了如何使用 NHibernate 进行分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我想在 ASP.NET 网页中填充 gridview 控件,其中仅包含显示的行数所需的数据.NHibernate 如何支持这一点?

For example, I want to populate a gridview control in an ASP.NET web page with only the data necessary for the # of rows displayed. How can NHibernate support this?

推荐答案

ICriteria 有一个 SetFirstResult(int i) 方法,表示第一个项目的索引您希望获得(基本上是页面中的第一个数据行).

ICriteria has a SetFirstResult(int i) method, which indicates the index of the first item that you wish to get (basically the first data row in your page).

它还有一个 SetMaxResults(int i) 方法,它表示您希望获得的行数(即您的页面大小).

It also has a SetMaxResults(int i) method, which indicates the number of rows you wish to get (i.e., your page size).

例如,此标准对象获取数据网格的前 10 个结果:

For example, this criteria object gets the first 10 results of your data grid:

criteria.SetFirstResult(0).SetMaxResults(10);

这篇关于如何使用 NHibernate 进行分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆