AutoMapper, . - , automapper .
TL; DR: AdminUserProfile.Roles IEnumerable<string>, , .
.ForMember(vm => vm.Roles, opt => opt.MapFrom(m => m.Roles.Select(r => r.Name)))
, AdminUserProfile.Roles - - string[], ICollection<string> List<string>.
AutoMapper linq, :
admins.Select(a => new AdminUserProfile{
Id = a.Id,
Name = a.Name,
Roles = a.Roles.Select(r => r.Name)
})
, Roles = a.Roles.Select(r => r.Name) . Roles ICollection<string>, a.Roles.Select IEnumerable<string>, .
automapper, Missing map from String to String., - ToList, - :
admins.Select(a => new AdminUserProfile{
Id = a.Id,
Name = a.Name,
Roles = a.Roles.Select(r => r.Name).ToList()
})
, Linq-to-entity, LINQ to Entities does not recognize the method ToList.
, "" automapper - :
admins.Select(a => new {
a.Id,
a.Name,
Roles = a.Roles.Select(r => r.Name)
})
.AsEnumerable()
.Select(a => new AdminUserProfile{
Id = a.Id,
Name = a.Name,
Roles = a.Roles.ToList()
})
, .
AdminUserProfile.Roles IEnumerable<string>.