简体   繁体   English

AutoMapper:映射子集合

[英]AutoMapper: Mapping child collections

AutoMapper Newbie Question. AutoMapper新手问题。

I have a source and destination DTO that have the same fields and child collections. 我有一个源和目标DTO具有相同的字段和子集合。 How can AutoMapper map these? AutoMapper如何映射这些?

Simplified source and destination DTOs share the same names: 简化的源和目标DTO共享相同的名称:

 Customer Orders Invoices CustomerInfo 

try 尝试

Mapper.CreateMap<Customer, CustomerModel>();
Mapper.CreateMap<Orders, OrderModel>();
Mapper.CreateMap<Invoices, InvoicesModel>();
Mapper.CreateMap<CustomerInfo, CustomerInfoModel>();
var mappedModel = Mapper.Map<Customer, CustomerModel>(customer);

here is another similar topic: AutoMapper - mapping child collections in viewmodel 这是另一个类似的主题: AutoMapper - 在viewmodel中映射子集合

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM