【发布时间】:2010-08-27 08:50:46
【问题描述】:
我将如何使用 nHibernate 2 ObjectDataSource
完成 Scott 在一次调用中所做的事情http://weblogs.asp.net/scottgu/archive/2006/01/07/434787.aspx
以下是我的数据访问方法
public IList GetListOfUser(int rows, int pageIndex) {
IList userList = null;
using (ITransaction tx = _session.BeginTransaction()) {
try {
userList = _session.CreateQuery("Select u from User u where u.DateSubmitted is not null")
.SetFirstResult(rows * (pageIndex - 1) + 1)
.SetMaxResults(rows)
.List();
tx.Commit();
} catch (NHibernate.HibernateException ex) {
tx.Rollback();
AppUtil.LogHelper.WriteLog(LogLevel.ERROR, ex.ToString());
throw;
}
}
return userList;
}
【问题讨论】:
-
澄清一下,您是否有兴趣在使用 NHibernate 的单个查询中获取分页列表以及总项目数?
-
嗨,是的,我一直在研究这个。我怎么能算出来呢? Select Count(u.UserId) as userCount from User u where u.DateSubmitted is not null 所以我可以得到一个 Int32 值,
标签: c# asp.net nhibernate objectdatasource