AutoMapper新手问题。
我有一个源和目标DTO,它们具有相同的字段和子集合。 AutoMapper如何映射这些?
简化的源和目标DTO共享相同的名称:
Customer Orders Invoices CustomerInfo
答案 0 :(得分:10)
试
Mapper.CreateMap<Customer, CustomerModel>();
Mapper.CreateMap<Orders, OrderModel>();
Mapper.CreateMap<Invoices, InvoicesModel>();
Mapper.CreateMap<CustomerInfo, CustomerInfoModel>();
var mappedModel = Mapper.Map<Customer, CustomerModel>(customer);
这是另一个类似的主题:AutoMapper - mapping child collections in viewmodel