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

学习笔记39_EF的DAL层(精)

时间:2017-06-29 22:18:37      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:dex   sas   index   model   name   contex   int   base   color   

通用的分页查询

public IQueryable<UserInfo> GetPage<T>(int pageSize,int pageIndex,out int total,

Expression<Func<UserInfo,bool>> whereLambda,

Expression<Func<UserInfo,T>> orderByLambda, bool IsAsc)

{

  total = db.UserInfo.where(whereLambda).count();

  var temp = dbContext.UserInfo.where(whereLambda). //u=>u.Name.contains("aaa")

  OrderByDesceding<UserInfo,T>(orderByLambda)//u=>u.Name

  .Skip(pageSize*(pageIndex-1))

  .Take(pageSize).AsQueryable();

}

//baseDal

public class BaseDal<T> where T: class,new()

{

  DataModelContainer db = new DataModelContainer();

  public IQueryable<T> GetEntities(Expression<Func<T,bool>> whereLambda)

  {

    return db.Set<T>().Where(whereLambda).AsQueryable();

  }

  //

  

  public IQueryable<T> GetPage<S>(int pageSize,int pageIndex,out int total,

  Expression<Func<T,bool>> whereLambda,

  Expression<Func<T,S>> orderByLambda, bool IsAsc)

  {

      total = db.Set<T>.where(whereLambda).count();

      var temp = dbContext.UserInfo.where(whereLambda). //u=>u.Name.contains("aaa")

      OrderByDesceding<T,S>(orderByLambda)//u=>u.Name

      .Skip(pageSize*(pageIndex-1))

      .Take(pageSize).AsQueryable();

  }

}

//那么,UserInfoDal

public class UserInfoDal:BaseDal<UserInfo>

{

  

}

学习笔记39_EF的DAL层(精)

标签:dex   sas   index   model   name   contex   int   base   color   

原文地址:http://www.cnblogs.com/pylblog/p/7096160.html

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