automapper가 이것을 매핑하도록하려면 어떻게해야합니까?
-
20-09-2019 - |
문제
이 수업이 있다고 말합니다.
public class Account
{
public int AccountID { get; set; }
public Enterprise Enterprise { get; set; }
public List<User> UserList { get; set; }
}
Automapper를 사용하여 계정 클래스를 매핑 할 때는 엔터프라이즈 클래스를 매핑하고 리턴 된 객체의 사용자 목록 (사용자 목록)을 맵핑하고 싶습니다. Automapper 가이 작업을 수행 할 수있는 방법은 무엇입니까?
감사!
해결책
Automapper는 엔터프라이즈 및 사용자 유형에 대한 구성을 제공하는 경우 박스에서이를 수행합니다.
구성은 다음과 같습니다.
Mapper.CreateMap<Account, AccountDto>();
Mapper.CreateMap<Enterprise, EnterpriseDto>();
Mapper.CreateMap<User, UserDto>();
이것은 컬렉션이 어떻게 매핑되는지를 보여줍니다.http://automapper.codeplex.com/wikipage?title=lists%20and%20arrays&referringtitle=home
다른 팁
맵핑하려는 각 유형 쌍에 대한 매핑을 만들어야합니다.
Mapper.createmapu003CAccount, AccountDto> ();
Mapper.createmapu003CEnterprise, EnterpriseDto> ();
Mapper.createmapu003CUser, UserDto> ();
주문은 중요하지 않습니다.
제휴하지 않습니다 StackOverflow