EF分页查询

/// <summary>
/// 查询所有商品
/// </summary>
/// <param name="pageNum">第几页</param>
/// <param name="pageSize">每页多少条数据</param>
/// <returns></returns>
// GET: api/<ShangpinController>
[HttpGet]
public async Task<ActionResult<IEnumerable<SHANGPIN>>> Get(int pageNum, int pageSize)
{
    var goods = await _dataContext.Shangpin
        .AsNoTracking()
        .OrderBy(g => g.SPDM)
        .Skip((pageNum-1)*pageSize+1)
        .Take(pageNum*pageSize)
        .ToListAsync();
    if (goods != null)
    {
        return new ObjectResult(new { code = 200, msg = "查询成功", count = goods.Count, result = goods });
    }
    return new ObjectResult(new { code = 404, sub_msg = "未查询到数据", msg = "" });
}

 

posted @ 2021-01-06 14:32  liessay  阅读(216)  评论(0编辑  收藏  举报