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>中进行的,这样可以避免排序字段不在主表,导致字段认不出的情况。

猜你喜欢

转载自www.cnblogs.com/ceci/p/9375852.html
ABP