Can Automapper map a paged list?

前端 未结 6 1956
我寻月下人不归
我寻月下人不归 2021-02-01 19:38

I\'d like to map a paged list of business objects to a paged list of view model objects using something like this:

var listViewModel = _mappingEngine.Map

        
6条回答
  •  自闭症患者
    2021-02-01 20:23

    AutoMapper does not support this out of the box, as it doesn't know about any implementation of IPagedList<>. You do however have a couple of options:

    1. Write a custom IObjectMapper, using the existing Array/EnumerableMappers as a guide. This is the way I would go personally.

    2. Write a custom TypeConverter, using:

      Mapper
          .CreateMap, IPagedList>()
          .ConvertUsing();
      

      and inside use Mapper.Map to map each element of the list.

提交回复
热议问题