views:

223

answers:

1

Hello, I was wondering if it is possible to map multiple DTO objects to a single ViewModel object using Automapper?

Essentially, I have multiple DTO objects and would like to display information from each on a single screen in ASP.NET MVC 2.0. To do so I would like to flatten the DTO objects (or parts of them...) into the Viewmodel and pass said viewmodel to the view. If I had one DTO this would be easy, but I've never seen it being done with multiple. Obviously there are a number of roundabout ways to do this (outside of automapper), but this is the approach that I would like to take if possible.

Thanks in advance,

JP

+3  A: 

You could create a composite DTO that holds two or more DTO objects and map the composite DTO to the output view model.

Alexander Groß
This is what we've done, and I found it works best. That composite presentation object then tends to start containing behavior etc. relating to the composite objects.
Jimmy Bogard
I started going down that route but then came to the realization that if have to manually map to a composite object before I can Map<>(), then what is this extra step affording me? Following this approach, you ensure that all your object mappings are managed via AutoMapper, but then live with the exception of manual mappings to composites. I'm not completely opposed to the idea, just sayin...
tbehunin