【C#接口】基础一

方法:
WhereIF
Where
OrderBy
ToPageList
代码:

public IActionResult GetNoticeList(string qh, string gglx, string gjc, int pageindex)
        {
            var dbContext = new DBContext();

            var pageSize = 10;//每页10条
            var totalCount = 0;
            var models = dbContext.Database.Queryable<IdpGonggao>()
                .WhereIF(!string.IsNullOrEmpty(qh), p => p.Qhdm == qh)
                .WhereIF(!string.IsNullOrEmpty(gglx), p => p.Gglx.Contains(gglx))
                .Where(p => p.Ggbt.Contains(gjc))
                .OrderBy(p => p.Fbsj, OrderByType.Desc)
                .ToPageList(pageindex, pageSize, ref totalCount).Select(p => new
                {
                    id = p.Id,
                    bt = p.Ggbt,
                    fbsj = p.Fbsj,
                    bmmc = p.Bmmc,
                    llcs = 0,//浏览次数暂未实现
                    sjlylj = p.Sjlylj
                }).ToList();

            var result = new {
                Totalcount = totalCount,
                Data = models
            };
                
            return Ok(new Result(true, ApiResponseCode.OK, "", result));
        }
发布了10 篇原创文章 · 获赞 0 · 访问量 174

猜你喜欢

转载自blog.csdn.net/weixin_42046939/article/details/104357770
今日推荐