我使用的分页工具是:AspNetPager框架:Nhibernate贴代码: public IList GetEntitesPage(int pageIndex, int pageSize)
{
string hql = "From MyUsers u Order By u.Liang_Id desc"; IList lst = null; sfy = mcf.BuildSessionFactory(); ISession session = sfy.OpenSession();
if (pageIndex < 1)
{
pageIndex = 1; lst = session.CreateQuery(hql).SetFirstResult(pageSize * (pageIndex - 1)).SetMaxResults(pageSize).List(); return lst;
}
else
{ pageIndex = pageIndex / 5; lst = session.CreateQuery(hql).SetFirstResult(pageSize * (pageIndex - 1)).SetMaxResults(pageSize).List(); return lst;
} session.Close(); return null;
}出错原因 每次跳转到第二页的时候 pageIndex 就递增十页,所以我就除以5,可第三页,第四页页呢?我总不能手写吧怎么样才灵活的处置?以前都是返回dataset 现在返回的是IList 就有这样的问题谢谢或者是Nhibetnate写dataset下面是在网上看到的:
Configuration cfg = new Configuration().Configure();
ISessionFactory sf = cfg.BuildSessionFactory();
// 得到扩展的Driver
ExSqlClientDriver driver = (ExSqlClientDriver)sf.ConnectionProvider.Driver;
// 打开数据库连接
IDbConnection conn = ((ISessionFactoryImplementor)sf).OpenConnection();
// 创建Command
IDbCommand cmd = conn.CreateCommand();
cmd.CommandText = "select * from infos";
DataSet ds = new DataSet();
// 创建DataAdapter
IDbDataAdapter da = driver.CreateDataAdapter();
da.SelectCommand = cmd;
// 填充Dataset
da.Fill(ds); 下面两句话有问题:
(ExSqlClientDriver)sf.ConnectionProvider.Driver; ((ISessionFactoryImplementor)sf).OpenConnection(); sf.ConnectionProvider
sf.OpenConnection点了不出东西是不是方法弄错?
用过nhibernate分页的大大们,怎么解决?谢谢!~
{
string hql = "From MyUsers u Order By u.Liang_Id desc"; IList lst = null; sfy = mcf.BuildSessionFactory(); ISession session = sfy.OpenSession();
if (pageIndex < 1)
{
pageIndex = 1; lst = session.CreateQuery(hql).SetFirstResult(pageSize * (pageIndex - 1)).SetMaxResults(pageSize).List(); return lst;
}
else
{ pageIndex = pageIndex / 5; lst = session.CreateQuery(hql).SetFirstResult(pageSize * (pageIndex - 1)).SetMaxResults(pageSize).List(); return lst;
} session.Close(); return null;
}出错原因 每次跳转到第二页的时候 pageIndex 就递增十页,所以我就除以5,可第三页,第四页页呢?我总不能手写吧怎么样才灵活的处置?以前都是返回dataset 现在返回的是IList 就有这样的问题谢谢或者是Nhibetnate写dataset下面是在网上看到的:
Configuration cfg = new Configuration().Configure();
ISessionFactory sf = cfg.BuildSessionFactory();
// 得到扩展的Driver
ExSqlClientDriver driver = (ExSqlClientDriver)sf.ConnectionProvider.Driver;
// 打开数据库连接
IDbConnection conn = ((ISessionFactoryImplementor)sf).OpenConnection();
// 创建Command
IDbCommand cmd = conn.CreateCommand();
cmd.CommandText = "select * from infos";
DataSet ds = new DataSet();
// 创建DataAdapter
IDbDataAdapter da = driver.CreateDataAdapter();
da.SelectCommand = cmd;
// 填充Dataset
da.Fill(ds); 下面两句话有问题:
(ExSqlClientDriver)sf.ConnectionProvider.Driver; ((ISessionFactoryImplementor)sf).OpenConnection(); sf.ConnectionProvider
sf.OpenConnection点了不出东西是不是方法弄错?
用过nhibernate分页的大大们,怎么解决?谢谢!~
public class AgentBusinessMethod
{
ISessionFactory factory;
ISession session;
Configuration cfg;
IQuery lqy;
public AgentBusinessMethod()
{
cfg = new Configuration();
cfg.AddAssembly("MyNHibernate");
factory = cfg.BuildSessionFactory();
session = factory.OpenSession();
} public IList GetResultList(string QueryString, int CurrentPageIndex, int PageSize)
{
lqy = session.CreateQuery(QueryString);
lqy.SetFirstResult((CurrentPageIndex - 1) * 2);
lqy.SetMaxResults(PageSize);
return lqy.List();
} public int RecordCount(string QueryString)
{
lqy = session.CreateQuery(QueryString);
return lqy.List().Count;
} public IList GetList(int CurrentPageIndex, int PageSize)
{
return GetResultList(" from AgentBusiness", CurrentPageIndex, PageSize);
} public int GetRecordCount()
{
return RecordCount(" from AgentBusiness");
}
}
AgentBusinessMethod AgentBusiness = new AgentBusinessMethod();
AspNetPagerData.RecordCount = AgentBusiness.GetRecordCount();
RepeaterData.DataSource =AgentBusiness.GetList(AspNetPagerData.CurrentPageIndex, AspNetPagerData.PageSize);
RepeaterData.DataBind(); //绑定
如果还不懂再问我,我qq:627529779