public IQueryable<T> LoadPageEntity<S>(int pageIndex, int pageSize, out int total, Func<T, bool> whereLambda, Func<T, S> orderByLambda, bool isASC) { var tmp = db.CreateObjectSet<T>().Where<T>(whereLambda); total = tmp.Count(); //分页 if (isASC) { tmp= tmp.OrderBy<T, S>(orderByLambda) .Skip<T>((pageIndex - 1) * pageSize) .Take<T>(pageSize); } else { tmp= tmp.OrderByDescending<T, S>(orderByLambda) .Skip<T>((pageIndex - 1) * pageSize) .Take<T>(pageSize); } return tmp.AsQueryable(); }
public ActionResult LoadData() { //表格传入的查询参数 //page:1 //rows:10 //sort:EmplID //order:ASC int pageIndex = Request["page"] == null ? 1 : int.Parse(Request["page"]); int pageSize = Request["rows"] == null ? 10 : int.Parse(Request["rows"]); string sort = Request["sort"] == null ? "ActionName" : Request["sort"].ToString(); bool order = Request["order"] == "asc" ? true : false; int total=0; var data = bll.LoadPageEntity(pageIndex, pageSize,out total, a => a.DelFlag == (short)DelFlagEnum.Normal, u => u.Remark, order); //ID, ActionName, HttpMethod, Url, DelFlag, Remark, SubTime, ActionGroupID var obj = new { total = total, rows = from u in data select new { u.ID, u.ActionName, u.HttpMethod, u.Remark, u.Url, u.DelFlag, u.SubTime,u.ActionGroupID } }; return Json(obj, JsonRequestBehavior.AllowGet); }
Razior不是可以传实体的吗,你这样做String转实体是有点麻烦?
z好参数是easyui的datagrid自动传的...
http://www.cnblogs.com/xuf22/archive/2011/12/08/2281333.html
很详细的例子,完全满足你的需求。
这位大侠提供的传送门,里面都是些异界生灵...我的等级暂时还不足以到此地练级....
不过还是感谢你.我会再回来看的.
@toward fai: 你可以先复制,先实现功能~呵呵~
internal DbSet<TEntity> dbSet;
// 通用查询语句
public virtual IQueryable<TEntity> Get( Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "") { IQueryable<TEntity> query = dbSet; if (filter != null) { query = query.Where(filter); } foreach (var includeProperty in includeProperties.Split (new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { query = query.Include(includeProperty); } if (orderBy != null) { return orderBy(query); } else { return query; } }
// 简化后的分页方法
public IQueryable<TEntity> GetPaged(Expression<Func<TEntity, bool>> filter, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy, int index, int size, out int total, string includeProperties = "") { return GetPaged(out total, filter, orderBy, includeProperties, index, size); } // 完整的分页方法 public IQueryable<TEntity> GetPaged(out int total, Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "", int index = 0, int size = 50) { int skipCount = index * size - size; var _reset = Get(filter, orderBy, includeProperties); total = _reset.Count(); _reset = skipCount == 0 ? _reset.Take(size) : _reset.Skip(skipCount).Take(size); return _reset.AsQueryable(); }
可以参考下