8
votes

AutoMapper Newbie Question.

I have a source and destination DTO that have the same fields and child collections. How can AutoMapper map these?

Simplified source and destination DTOs share the same names:

Customer
    Orders
       Invoices
    CustomerInfo
1
Have you tried it? It should map child collections automatically provided you have maps for each of the types. (Order, Invoice, etc.)D Stanley

1 Answers

13
votes

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