I'm mapping a list to another list with Automapper, but it seems that my items are not copied.
Here is my code:
var roles = userRepo.GetRoles(null).ToList();
Mapper.CreateMap < List<Domain.Role>, List<Role>>();
var mappedRole = Mapper.Map<List<Domain.Role>, List<Role>>(roles); //the count is 0, list empty :(
Mapper.AssertConfigurationIsValid();
Domain.Role
public class Role
{
public int RoleId { get; set; }
public string RoleName { get; set; }
public List<User> Users { get; set; }
}
Role
public class Role
{
public int RoleId { get; set; }
public string RoleName { get; set; }
}
Don't create maps between lists and array, only between the types:
Mapper.CreateMap<Domain.Role, Role>();
and then:
var mappedRole = Mapper.Map<List<Domain.Role>, List<Role>>(roles);
AutoMapper handles lists and arrays automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With