通用的分页查询
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>
{
}