// // GET: /AdminConsole/Article/ public ActionResult Index(ArticleCond cond) { int count = 0; var data = bll.GetPageWithCategory(cond, out count, p => p.CreateTime, false); ViewBag.PageList = new PagedList <Article>(data, cond.PageIndex, cond.PageSize, count); return(View()); }
// // GET: /Article/ public ActionResult Index(ArticleCond cond) { int count = 0; ViewBag.Categories = catBll.LoadEntity(p => p.ParentId == "0").OrderBy(p => p.Sort).ToList(); var data = articleBll.GetPageWithCategory(cond, out count, p => p.CreateTime, false); ViewBag.PageList = new PagedList <Article>(data, cond.PageIndex, cond.PageSize, count); return(View()); }
public List <Article> GetPageWithCategory <S>(ArticleCond cond, out int total, System.Linq.Expressions.Expression <Func <Article, S> > orderLambda, bool isAsc) { Expression <Func <Article, bool> > whereLambda = p => true; if (!string.IsNullOrWhiteSpace(cond.CategoryId)) { var artIds = art_catDal.LoadEntity(p => p.CategoryId == cond.CategoryId).Select(p => p.ArticleId); whereLambda = whereLambda.And(p => artIds.Contains(p.Id)); } //多次访问数据库 ,使用到遍历查询不要使用延迟加载,ToList()减少查询次数,降低数据库压力 var data = dal.LoadPageEntity(whereLambda, cond.PageIndex, cond.PageSize, out total, orderLambda, isAsc).ToList(); return(GetArticleListWithCategory(data)); }