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 Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: