AutoMapper – map one list to another

Create a mapping from list to list:

mapper.Map<List<sourceModel>, List<destinationModel>>(dataSourceList);

So e.g:

var carsVM = mapper.Map<List<Car>, List<CarVM>>(cars);

Where ‘cars’ is of the List type and of course before it, we need to add a map to AutoMapper config with the .CreateMap and .ForMember methods for the appropriate properties if needed.

Leave a comment