views:

140

answers:

1

Hi all,

I am using AutoMapper in my project along with, NHibernate and ASP.NET MVC 2.

As the title states, if I have a list of DTOs or a DTO inside the parent DTO that I am mapping to the View Model, should I flatten out the inner DTOs as well ?

Edit:

Should I write view model classes for the internal objects as well or should I use them as it is (as DTOs with lazy loading, due to NHibernate)?

Thanks

A: 

When you map an object to object, AutoMapper trying automatically get all the destination objects properties mapped, including complex properties.

You probably want to test that all the properties of the destination object are mapped. You can achieve that with:

Mapper.AssertConfigurationIsValid();

About your edit: the ViewModel needs to be entirely dependent on the model object. So internal objects needs to be as well specific to the view model.

Mendy
Question Updated, thanks for the reply, but its not what I am looking for, I already took care to see if the configuration is valid, I am asking more in terms of a good pratice to follow when mapping hierarchical objects.
Mahesh Velaga
About your edit: the ViewModel needs to be entirely dependent on the model object. So internal objects needs to be as well specific to the view model.
Mendy
So does that mean that I have to write custom objects to be mapped to the internal DTOs ? in my case I have a 3 level hierarchy and stuff, its a little complicated, so I was trying to avoid, writing custom objects to map till the leaf level. But, if it is how people follow then I will flatten and map them.
Mahesh Velaga
This is why I am looking for inputs from others
Mahesh Velaga
Your comment helped me to find what I wanted, so I edited your answer with your comment and accepted. Thanks
Mahesh Velaga