NHibernate分页

   public  IList < Orders >  GetUserOrderByUserID( string  userid,  int  PageIndex,  int  PageSize,  out   long  count)
        {
            
using  (ISession _session  =   base .GetSession())
            {
                var hql 
=   " select count(*) from Orders where userid=:userid " ;
                IQuery query 
=  _session.CreateQuery(hql);
                query.SetString(
" userid " , userid);
                
object  obj  =  query.UniqueResult();
                
long .TryParse(obj.ToString(),  out  count);


                var list 
=  from p  in  _session.Linq < Orders > ()
                   .Where(p 
=>  p.UserID  ==  userid)
                   .OrderByDescending(p 
=>  p.Otime)
                   .Skip((PageIndex 
-   1 *  PageSize)
                   .Take(PageSize)
                           select p;

                
return  list.ToList < Orders > ();
            }
        }


你可能感兴趣的:(Hibernate)