我有兩個源對象:映射兩個源對象到三個對象
public class Book
{
public int Id {get;set;}
public IList<Unity> Unities {get;set;}
}
public class Unity
{
public int Id {get;set;}
public string Title {get;set;}
}
和三個目標對象:
public class DtoBook
{
public int Id {get;set;}
public DtoOrganization Organization {get;set;}
}
public class DtoOrganization
{
public int Id {get;set;}
public IList<DtoUnity> Unities {get;set;}
}
public class DtoUnity
{
public int Id {get;set;}
public string Title {get;set;}
}
我想映射兩個源對象簿和統一到三個dto對象,但不存在組織源對象。我怎麼用Automapper來做到這一點?
謝謝!
後我的實際代碼Automapper代碼:
public static void Configure()
{
Mapper.Reset();
Mapper.CreateMap<Unity, Model.Organization>();
Mapper.CreateMap<Book, Model.Manifest>()
.ForMember(x => x.Version, y => y.UseValue("1.1"));
Mapper.AssertConfigurationIsValid();
}
public static Model.Manifest Map(Book book)
{
Configure();
Model.Manifest dtoManifest = Mapper.Map<Book, Model.Manifest>(book);
return dtoManifest;
}
看看'AutoMapper'。 – rosko
這裏是一個鏈接:http://automapper.codeplex.com/ –
但是,我什麼都看不到! –