AutoMapper: How to transform object graph to into?
Posted
by epitka
on Stack Overflow
See other posts from Stack Overflow
or by epitka
Published on 2010-05-04T18:32:45Z
Indexed on
2010/05/04
18:38 UTC
Read the original article
Hit count: 202
automapper
If I have a one-to-many relationship and I want to transorm this into a list of flat Dto-s where some attributes of parent and some of child appear in a dto, is this something that is supported out-of-box with AutoMapper? For example if I have something like this
Parent
1. ParentId
2. ParentAttr1
3. List<Child>
Child
1. ChildId
2. ChildAttr1
2. ChildAttr2
Dto
1. ParentId
2. ChildId
2. ChildAttr1
3. ChildAttr2
How do I project Parent into a Dto where for each child in parent I will get an instace of Dto?
I've setup two maps Parent->Dto and Child->Dto but just doing _mapper.Map(parentInstance) only projects parents attributes. Does this have to be done in two steps, where I would iterate children myself?
© Stack Overflow or respective owner