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
Using jrummell's answer, I created an extension method that works with Troy Goode's PagedList. It keeps you from having to put so much code everywhere...
public static IPagedList ToMappedPagedList(this IPagedList list)
{
IEnumerable sourceList = Mapper.Map, IEnumerable>(list);
IPagedList pagedResult = new StaticPagedList(sourceList, list.GetMetaData());
return pagedResult;
}
Usage is:
var pagedDepartments = database.Departments.OrderBy(orderBy).ToPagedList(pageNumber, pageSize).ToMappedPagedList();