arch/UnitOfWork

GetPagedListAsync with mapping in selector and includes don't work

eoehen opened this issue · 1 comments

var result2 = await unitOfWork.GetRepository<Entity>()
                .GetPagedListAsync(
                    mapping => mapper.Map<EntityDto>(mapping),
                    null,
                    mapping => mapping.OrderBy(map => map.Name),
                    include: source => source.Include(mapping => mapping.Template),
                    queryParameters.PageIndex, queryParameters.PageSize);

The combination of mapping => mapper.Map<EntityDto>(mapping) and an include statement include: source => source.Include(mapping => mapping.Template) dosn't work.

The same stuff in several steps is working well.
f.e. first load without Automapper mapping and second map the entity into the EntityDto after loading pagedList.

This example works correct.

var result = await unitOfWork.GetRepository<Entity>()
                .GetPagedListAsync(
                    mapping => mapping,
                    null,
                    mapping => mapping.OrderBy(map => map.Name), 
                    include: source => source.Include(mapping => mapping.Template),
                    queryParameters.PageIndex, queryParameters.PageSize);

var dtoItems = mapper.Map<List<EntityDto>>(result.Items);

Analyse:

  • Dataloading with include himself is working correct.
  • Automapping himself ist working correct.

But the combination of Dataloading and Automapping in the selection dosn't work.

FYI: GetFirstOrDefaultAsync is working.

var mappingDto = await unitOfWork.GetRepository<Entity>()
	.GetFirstOrDefaultAsync(
		mapping => mapper.Map<EntityDto>(mapping),
		mapping => mapping.Id == id, 
		include: source => source.Include(mapping => mapping.Template));