Mapping string to List<string> and vice versa using Automapper
There is something similar to your questiong here, please can you check this out AutoMapper: Collection to Single string Property
PS: This is an example for mapping collection to single string property probably your example should look like below;
Mapper.CreateMap<User, UserEditViewModel>()
.ForMember(dest => dest.Roles,
m => m.MapFrom(src => src.Role.Split(',').ToList()));
And mapping the instances like below;
User myUser = new User();
myUser.Role = "r1,r2,r3,r4,r5";
myUser.UserID = 1;
myUser.Username = "MyUserName";
UserEditViewModel result = Mapper.Map<UserEditViewModel>(myUser);
2020 Edit: Since Expression.Call
API does not support optional parameter and you should Replace src.Role.Split(',')
with src.Role.Split(',', System.StringSplitOptions.None)
or src.Role.Split(',', System.StringSplitOptions.RemoveEmptyEntries)