12
예를 들어 여러 클래스로 맵핑 할 필요가있는 클래스가 1 개 있습니다.Automapper가 중첩 클래스로 매핑
public class UserBM
{
public int UserId { get; set; }
public string Address { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string State { get; set; }
public int CountryId { get; set; }
public string Country { get; set; }
}
이 대상 클래스 (도메인 모델)입니다 방법은 다음과 같습니다 :
public abstract class User
{
public int UserId { get; set; }
public virtual Location Location { get; set; }
public virtual int? LocationId { get; set; }
}
public class Location
{
public int LocationId { get; set; }
public string Address { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
public string State { get; set; }
public virtual int CountryId { get; set; }
public virtual Country Country { get; set; }
}
이 얼마나 내 automapper
이
내가 (보기 모델)에서 매핑있어 소스 현재지도 만들기 :Mapper.CreateMap<UserBM, User>();
Mapper.Map<UserBM, Location>(...)
를 사용하여Location
속성을지도? – xrklvs[SO] (http://stackoverflow.com/questions/5984640/automapper-class-and-nested-class-map-to-one-class)에 비슷한 스레드가 있습니다. 여기서 매핑의 최종 비트를 더 좋아합니다. :'opt.MapFrom (src => Mapper.Map (src)') 대신'opt => opt.MapFrom (src => src)'를 사용한다. –
superjos