public IQueryable<BBS_Theme> GetListPage(int PageSize, int PageIndex, NameValueCollection nvcParamWhere, NameValueCollection nvcorderby, ref int AllCount) { #region where var searchPredicate = PredicateExtensions.True<BBS_Theme>(); if (nvcParamWhere != null) { foreach (string key in nvcParamWhere) { string condition = string.Empty; switch (key) { #region case "ID": condition = nvcParamWhere[key]; searchPredicate = searchPredicate.And(u => u.ID.Equals(condition)); break; case "LableID": condition = nvcParamWhere[key]; searchPredicate = searchPredicate.And(u => u.LableID.Equals(condition)); break; default: break; #endregion } } } #endregion #region queryable var linq = (from a in db.BBS_Theme select a) .Where(searchPredicate); #endregion #region orderby if (nvcorderby != null) { foreach (string key in nvcorderby) { string condition = string.Empty; switch (key) { case "ID": condition = nvcorderby[key]; if(bool.Parse(condition)) { linq = linq.OrderBy(o=>o.ID); } else { linq = linq.OrderByDescending(o => o.ID); } break; //........省略n个case default: break; } } } #endregion AllCount = linq.Count(); linq = linq.Skip(PageSize * (PageIndex - 1)).Take(PageSize); return linq; }