我发现了非常有趣的使用 nhibernate 分页的教程 http://blogs.planetcloud.co.uk/mygreatdiscovery/post/Simple-paging-with-ASPNET-MVC-and-NHibernate.aspx
这些怎么能public PagedList<PSScript> GetPaged(int pageIndex, int pageSize)
重写查询以便在没有 future 的情况下使用(这样做的主要原因是我应该有其他数据库的工作版本,例如 firbird 等)
或者,如果您有其他一些有趣的分页教程要分享,请分享。
谢谢
最佳答案
您可以简单地创建没有 Futures
的查询。唯一的区别是您将有两次到数据库的往返而不是一次。我认为这在您的场景中不会成为问题。
这样的事情应该有效:
using (ISession session = NHibernateHelper.OpenSession())
{
var rowCount = session.CreateCriteria<PSScript>()
.SetProjection(Projections.RowCount())
.UniqueResult<Int32>();
var results = session.CreateCriteria<PSScript>()
.SetFirstResult((pageIndex - 1) * pageSize)
.SetMaxResults(pageSize)
.ToList<PSScript>();
return new PagedList<PSScript>(results, pageSize, pageSize, rowCount);
}
关于c# - 使用 nhibernate 和 mvc 进行分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12194196/