Can Automapper map a paged list?

前端 未结 6 1886
我寻月下人不归
我寻月下人不归 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:21

    If you're using Troy Goode's PageList, there's a StaticPagedList class that can help you map.

    // get your original paged list
    IPagedList pagedFoos = _repository.GetFoos(pageNumber, pageSize);
    // map to IEnumerable
    IEnumerable bars = Mapper.Map>(pagedFoos);
    // create an instance of StaticPagedList with the mapped IEnumerable and original IPagedList metadata
    IPagedList pagedBars = new StaticPagedList(bars, pagedFoos.GetMetaData());
    

提交回复
热议问题