浏览器标题切换
浏览器标题切换end

Intern Day26 - Linq中用Take和Skip实现分页查询操作

        [Route("api/patients")]
        [HttpGet]
       // [HttpGet("pat0")]
        public List<Patient> list(string keyword, int pageIndex, int pageSize)
        {
            var skip=pageSize*(pageIndex-1);
            var patient = _patientDbContext.Patients
                .Where(it=>it.Name.Contains(keyword)) // Where属于Linq下的
                // 从两端模糊匹配
                // 相当于pgsql中的
                // select * from platform.patient where name like '%keyword%'
                // offset 40 limit 20; 
               
                // Skip和Take一般放一起用,一般用于分页
                .Skip(skip) // 跳过前skip个元素
                .Take(pageSize) // 获取前pageSize个元素
                
                .ToList();
            return patient;
        }

带排序的写法,PageSize参数由前端传给后端:

var pageFiles = validFiles.OrderByDescending(x => x.CreateTime).Skip((input.PageIndex - 1) * input.PageSize).Take(input.PageSize).ToList();
posted @ 2021-03-15 14:35  抓水母的派大星  阅读(101)  评论(0)    收藏  举报