ABP实战--分页排序

  待完成。。。

public async Task<DatatablesResultDto<TaskDto>> GetList(KeywordDatatablesRequestDto input)
        {
            var result = new PagedResultDto<TaskDto>();

            var query = Repository
                //.GetAll()
                .GetAllIncluding(t => t.AssignedPerson)
                .WhereIf(!input.Keyword.IsNullOrEmpty(), t => t.Title.Contains(input.Keyword) || t.Description.Contains(input.Keyword));
            var total = query.Count();  //分页前获得总数
            var queryDtos = query.ProjectTo<TaskDto>();
            //var taskDtos = ObjectMapper.Map<IQueryable<TaskDto>>(query);  //这里会报错,Mapping types:InternalDbSet`1->IQueryable`1

            queryDtos = queryDtos.OrderBy(input.OrderBy).PageBy(input);
            var taskDtoList = await queryDtos.ToListAsync();
            return new DatatablesResultDto<TaskDto>(total, taskDtoList);
        }

  注意这里的排序是在IQueryAble<Dto>中进行的,这样可以避免排序字段不在主表,导致字段认不出的情况。

上一篇:Python pip安装时You are using pip version 9.0.1, however version 18.0 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command.


下一篇:Linux学习记录