Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoMapper: Mapping child collections

Tags:

c#

automapper

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
like image 683
Ian Vink Avatar asked Dec 07 '12 17:12

Ian Vink


1 Answers

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

like image 84
Hink Avatar answered Sep 20 '22 18:09

Hink