Моя модель обслуживания содержит список строк.
Моя модель представления содержит список типа RolesViewModel.
RolesViewModel имеет строковое свойство с именем RoleName.
Ниже приведены мои модели
Код: Выделить всё
public class UserViewModel
{
[Display(Name = "Email address")]
[Required(ErrorMessage = "The email address is required")]
[EmailAddress(ErrorMessage = "Invalid Email Address")]
public string Email { get; set; }
public List Roles { get; set; } = new List();
}
public class RolesViewModel
{
public RolesViewModel(string roleName)
{
RoleName = roleName;
}
public string RoleName { get; set; }
}
//Service Model
public class User
{
public string Email { get; set; }
public List Roles { get; set; } = new List();
}
//Service Return Model
public class ServiceResponse
{
public bool Success { get; set; } = false;
public Data.Enums.Exception Exception { get; set; }
public T ResponseModel { get; set; }
///
/// Allows Service Response to be cast to a boolean.
///
///
public static implicit operator bool(ServiceResponse response)
{
return response.Success;
}
}
Код: Выделить всё
List viewModel = serviceResponse.ResponseModel.Adapt();
Код: Выделить всё
public class Mapping : IRegister
{
public void Register(TypeAdapterConfig config)
{
config.NewConfig();
config.NewConfig();
config.NewConfig
();
config.NewConfig();
config.NewConfig();
}
}
Код: Выделить всё
public class Mapping : IRegister
{
public void Register(TypeAdapterConfig config)
{
config.NewConfig();
config.NewConfig();
config.NewConfig
();
config.NewConfig().Map(dest => dest.Roles.Select(t => t.RoleName.ToString()).ToList(), src => src.Roles);
config.NewConfig().Map(src => src.Roles, dest => dest.Roles.Select(t => t.RoleName.ToString()).ToList());
config.NewConfig();
}
}
"Недопустимое приведение из "System.String" к "ViewModels.RolesViewModel".
Может ли кто-нибудь посоветовать мне, какая конфигурация мне нужна в моем классе картографирования?
Подробнее здесь: https://stackoverflow.com/questions/489 ... of-strings