2
프리젠 테이션 모델을 만들었으며 AutoMapper와 함께 ViewModel에 매핑하려고합니다. ViewModel은 partials를 사용하고 있기 때문에 다른보기/부분에 대해서도 KeyboardsViewModel을 재사용하기 때문에 composite /입니다.지도 ViewModel/partials with AutoMapper
이 프리젠 테이션 모델을 ViewModel에 어떻게 매핑 (설정 매핑) 할 수 있습니까? 이것이 올바른 접근 방법입니까?
감사합니다.
public class MainPresentationModel : BasePresentationModel
{
// Should map into the MainViewModel.Keyboards.Keyboards
public int DefaultKeyboard { get; set; }
// Should map into the MainViewModel.Keyboards.DefaultKeyboard
public IList<Keyboard> Keyboards { get; set; }
// Should map into the MainViewModel.Something
public string Something { get; set; }
}
public class MainViewModel : BaseViewModel
{
public KeyboardsViewModel Keyboards { get; set; }
public string Something { get; set; }
}
public class KeyboardsViewModel
{
public int DefaultKeyboard { get; set; }
public IList<Keyboard> Keyboards { get; set; }
}
편집 : 는 시도 후 나는이 하나 개의 옵션이라고 생각 :
Mapper.CreateMap<MainPresentationModel, MainViewModel>()
.ForMember(d => d.Keyboards, opt => opt.MapFrom(src => src));
Mapper.CreateMap<MainPresentationModel, KeyboardsViewModel>();
작동 것 같다, 그러나 이것은 최적의/올바른 방법 인 경우 나는 ...
를 확실하지 않다