편집 : 제목이 잘못되었습니다. 소스 목록에서 중첩 된 모델의 소스 목록으로 매핑하려고합니다.원본 중첩 컬렉션에서 다른 컬렉션으로 AutoMapper 맵
중첩 모델에 나열된 다른 목록에 목록을 매핑하는 데 문제가 있습니다. 종류의 종류와 평평하지 않은 종류. 문제는 매핑을 수행하는 방법을 모른다는 것입니다. ...
이 항목 및 ItemModel 이미 매핑이 그들 사이에 정의public class DestinationModel
{
public DestinationNestedViewModel sestinationNestedViewModel { get; set; }
}
public class DestinationNestedViewModel
{
public List<ItemModel> NestedList { get; set; }
}
public class SourceModel
{
public List<Item> SourceList { get; set; }
}
이
내가이 방법을 수행 할 수 없습니다
: 여기 내 셋업 매핑에 내 실패한 시도를 따라입니다Mapper.CreateMap<SourceModel, DestinationModel>()
.ForMember(d => d.DestinationNestedViewModel.NestedList,
opt => opt.MapFrom(src => src.SourceList))
ERROR :
식 'D => d.DestinationNestedViewMode l.NestedList '최상위 member.Parameter의 이름으로 확인해야합니다 NestedList = t.SourceList이
.ForMember(d => d.DestinationNestedViewModel,
o => o.MapFrom(t => new DestinationNestedViewModel { NestedList = t.SourceList }))
문제 : lambdaExpression
나는 다음과 같이 뭔가를 시도했다. 각각 서로 다른 요소, ItemModel 및 항목을 각각 포함합니다. 따라서 매핑해야합니다.
어떻게 매핑합니까?
:
를 그런 다음 당신이해야합니다 모든
Source
과Destination
사이의 전화Mapper.Map
입니다 그러나 Item에서 ItemModel 로의 매핑을 생성해야하므로 AutoMapper는 Item 객체를 ItemModel 객체에 매핑하는 방법을 알고 있습니다. –Item과 ItemModel 사이에 이미 매핑이 정의되어 있지만 NestedList가 DestinationModel 에 속해 있고 NestedList가 DestinationNestedViewModel에 속해 있기 때문에 매핑이 트리거되지 않습니다. Automapper는 매핑 할 때 모델의 2 티어를 처리 할 수 없습니다 (적어도 시도한 방식이 아닙니다) – getit