Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping a large List of Entities to a PagedList of ViewModels

How to use PagedList in a web application based on ASP MVC in combination with ViewModels.

I want to make a PagedList of Viewmodels, so first I have to map the Entities to Viewmodels.

When I fetch a large list, it it very slow because first the mapping is executed before the PagedList is made (so the whole List of Entities is fetched).

What is the best way to solve this issue?

IEnumerable<InvoiceData> invoiceData = dataService.GetInvoiceData(locationId);

Mapper.CreateMap<InvoiceData, ViewModelInvoiceData>();
IEnumerable<ViewModelInvoiceData> vmInvoiceData = Mapper.Map<IEnumerable<InvoiceData>, IEnumerable<ViewModelInvoiceData>>(invoiceData);

IPagedList<InvoiceDataViewModel> pagedListVMInvoiceData = vmInvoiceData.ToPagedList(page, pageSize);

(I also use a mapping framework, but it's of course the same problem with a custom mapper class)

like image 250
FilipRot Avatar asked Nov 12 '22 18:11

FilipRot


1 Answers

Why you didn't page your data on server? And after that create manual pager like in example 2 from troygoode / PagedList ?

like image 91
Dmytro Rudenko Avatar answered Nov 15 '22 12:11

Dmytro Rudenko