5
映射DTO到域對象比方說,我有兩個對象,我想映射:AutoMapper:與子對象
// Domain objects
public class MyDomainObject
{
public string SimpleText { get; set; }
public int SimpleNumber { get; set; }
public MySubObject ComplexValue { get; set; }
}
public class MySubObject
{
public int Id { get; set; }
public string Name { get; set; }
}
// DTOs
public class MyDto
{
public string SimpleText { get; set; }
public int SimpleNumber { get; set; }
public int ComplexValueId { get; set; }
public string ComplexValueName { get; set; }
}
// Mapping config
Mapper.CreateMap<MyDomainObject, MyDto>();
THS將正常工作,而無需額外的配置,因爲AutoMapper將着眼於駝峯規則和向下鑽取。
現在我想映射DTO回域對象:
Mapper.Map<MyDto, MyDomainObject>(dto, domainObj);
什麼將最好的/簡單的映射配置是實現呢?
相關:http://stackoverflow.com/questions/3145062/using-automapper-to-unflatten-a-dto –