tags:

views:

44

answers:

2

Hi guys,

I have recently started using automapper and it has work fine for me so far. I have been mapping domain objects to corresponding dtos and by default all source properties get mapped to their matching destination properties. I have been using code as follows:

Mapper.CreateMap<Node, NodeDto>();
var nodeDto = Mapper.Map<Node, NodeDto>( node );

Now I have got into a situation where I would like to map only some of the properties of the source object. There are collection properties in the source object that I do not want to be mapped to the matching destinatin properties. Is there a way to achieve that?

Thanks Nabeel

+4  A: 

You could specify the properties to ignore like this:

Mapper.CreateMap<Node, NodeDto>()
      .ForMember(dest => dest.SomePropToIgnore, opt => opt.Ignore())
Darin Dimitrov
Brilliant! Thanks Darin
nabeelfarid
Hi Darin, Could you help me with an another issue I have just ran into http://stackoverflow.com/questions/3336688/issue-with-ignoring-nested-properties-using-automapper Thanks
nabeelfarid
and another issue on http://stackoverflow.com/questions/3336931/issue-with-ignoring-base-class-property-in-child-classes-mappings-using-automappe
nabeelfarid
A: 

or you could use this where not going to need to ignore anything cuz collections are not mapped by default

Omu

related questions