In several projects I am using the mapping functions of AutoMapper. I will use the object Car as an example through the full question.
First my set-up:
I define my maps with profiles:
public class CarProfile : Profile
{
public CarProfile()
{
CreateMap<Car, CarResponse>();
}
}
I initialize AutoMapper in ASP.NET Core Web API with:
services.AddAutoMapper();
Using the NuGet packages AutoMapper
and AutoMapper.Extensions.Microsoft.DependencyInjection
The mapper is automically injected in the constructor and set as a private field _mapper
.
Eventually I map a collection with the following piece of code:
_mapper.Map<IEnumerable<Car>, IEnumerable<CarResponse>>(_context.Cars);
It's also worth to mention that _context.Cars
is in this case an DbSet<T>
.
Now my actual question is: would it be different if I would use an array
instead of a IEnumerable
.
Example given:
_mapper.Map<Car[], CarResponse[]>(_context.Cars);
Please consider performance, clean code and behavioural differences.