码迷,mamicode.com
首页 > 其他好文 > 详细

EF查询分页

时间:2015-11-16 17:26:50      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

  static List<T> GetPageList(Func<T,bool> whereLambda,Func<T,object> orderLambda,int pageSize,int pageIndex)
        where T:class
    {
        EFEntities context=new EFEntities();//实例化上下文
        var list=context.Set<T>().where(whereLambda).orderByDescending(orderLambda).Skip((pageIndex-1)*pageSize).Take(pageSize).Select(s=>s);
        return list.ToList(); 
    }
        //完善后
     public
List<dynamic> getPageDate<T, TKey>(Expression<Func<T, dynamic>> select, Expression<Func<T, bool>> where, Expression<Func<T, TKey>> order, int pageIndex, int pageSize, out int Total) where T : class { CIK_NewsEntities db = new CIK_NewsEntities(); Total = db.Set<T>().Where(where).Count(); var list = db.Set<T>().Where(where).OrderByDescending(order).Select(select).Skip((pageIndex - 1) * pageSize).Take(pageSize); return list.ToList(); }
      //使用方法
     int
Total_ = 0; rptCate.DataSource = getPageDate<Category, int>(c => new { c.Name, c.CreatedDate, c.CreatedBy }, c => c.Id > 0, c => c.Id, 2, 4, out Total       _); rptCate.DataBind(); this.Label1.Text = Total_.ToString();

 

EF查询分页

标签:

原文地址:http://www.cnblogs.com/ailongfei/p/4969217.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!