Nhibernate 分页

public IList<Student> GetStudentByPage(int pageSize, int pageIndex, string SName)

        {

            ISession session = NHibernateHelper.GetCurrentSession();

            ITransaction trans = session.BeginTransaction();

            //HQL查询

            IList<Student> studentList = new List<Student>();

            //string sql = "from Student";

            //studentList = session.CreateQuery(sql)

            //    .SetFirstResult((pageIndex - 1) * pageSize)

            //    .SetMaxResults(pageSize)

            //    .List<Student>();



            //SQL查询



            //studentList = session.CreateSQLQuery("SELECT * FROM Student")

            //    .SetFirstResult((pageIndex - 1) * pageSize)

            //    .SetMaxResults(pageSize)

            //    .SetResultTransformer(Transformers.AliasToBean<Student>()).List<Student>();

            return studentList;

        }
View Code

 

你可能感兴趣的:(Hibernate)