联表查询,判断追加条件,对集合分页

 public ActionResult Index(string titleName, string nickName, int pageIndex = )
{
var data = from m in _db.AppArticleComment
join o in _db.AppArticle on m.ArticleId equals o.ArticleId
where (string.IsNullOrEmpty(nickName) ? true : m.NickName == nickName)//在此判断加条件,当变量值null需要转为整型时会抱异常
select new AppArticleCommentModel()
{
Id = m.Id,
OId = m.OId,
MId = m.MId,
NickName = m.NickName,
Comment = m.Comment,
Good = m.Good,
Created = m.Created,
IsHorizontal = m.IsHorizontal,
Version = m.Version,
From = m.From,
ArticleName = o.Title }; if (!string.IsNullOrEmpty(titleName))
{
//也可在此判断添追加条件
data = data.Where(m => m.ArticleName.Contains(titleName));
} int total = ;
int pageSize = ;
//对集合进行分页
var query = data.OrderByDescending(m => m.Created)
.Skip(pageSize * (pageIndex - )).Take(pageSize); var list = query.ToList();
total = data.Count(); PagingHelper<AppArticleCommentModel> dataPaging = new PagingHelper<AppArticleCommentModel>(, list);//初始化分页器
dataPaging.PageIndex = pageIndex;//指定当前页
dataPaging.PageCount = (int)Math.Ceiling(total / (double)pageSize);
dataPaging.PageSize = pageSize;
dataPaging.TotalCount = total; return View(dataPaging);//返回分页器实例到视图
}

最新文章

  1. LDAP binary字段读取
  2. mysql实验
  3. MS SQL SERVER索引优化相关查询
  4. 边工作边刷题:70天一遍leetcode: day 82-1
  5. PHP json_decode object时报错Cannot use object of type stdClass as array
  6. C#连接mysql实例
  7. codeforce 702D Road to Post Office 物理计算路程题
  8. Ext入门学习系列(五)表格控件(1)
  9. 【POJ1182】 食物链 (带权并查集)
  10. 烟雾检测笔记1--《Video-based smoke detection with histogram sequence of LBP and LBPV pyramids》解析、实现
  11. 教训:TOJ[4081] God Le wants to know the directory
  12. 《JS正则表达式》
  13. Spring源码情操陶冶-tx:advice解析器
  14. 0326 iframe和video experience
  15. day 54 jQuery, part-1
  16. 英语口语练习系列-C29-鸟类-辨别身份-断弦的琴
  17. 部署MySQL自动化运维工具inception+archer
  18. SELECT版FTP
  19. Python 练习:简单的购物车
  20. 架构 : 三层架构、MVC、MVP、MVVM

热门文章

  1. COM调用 &ndash; VB、PB
  2. SpringMVC整合MongoDB开发 架构搭建
  3. 解决box-flex不均等分的问题
  4. mysql 不是主键不能删除的保护问题解决办法?
  5. android开发--(SimpleAdapter)运用
  6. div高度自适应(父元素未知,所有高度跟随子元素最大的高度)
  7. MySQL备份学习
  8. Mysql数据库的使用经验总结
  9. ORACLE数据库存储结构
  10. cognos函数学习