Automapper : partial mapping?

Up vote 1 down vote favorite share g+ share fb share tw.

I am using Automapper to transfer data from objectA to objectB classe ObjectA { string Title; string Summary; } classe ObjectB { string Title; string Summary; IAddress Address; } I created this kind of mapping between the two objects AutoMapper.Mapper.CreateMap() . ForMember(dest => dest. Title, src => src.

MapFrom(s => s. Title)) . ForMember(dest => dest.

Summary, src => src. MapFrom(s => s. Summary)) .

ForMember(dest => dest. Address, src => src.Ignore()) I create my ObjectB and fill all its properties including Address When I call the mapper, I was expecting it to override Title and Summary and ignore Address ObjectB = Mapper. Map(objectA); Actually, it is throwing and exception for Address.

What am I doing wrong? UPDATE To express it differently, I have my objectB and I want to update part of it with data coming from ObjectA. When I say Ignore, I mean leave the data the way they already are automapper link|improve this question edited Mar 21 '11 at 8:47 asked Mar 21 '11 at 7:58user385411198111 57% accept rate.

It might be useful to know what exception you received... – JoDG Mar 21 '11 at 8:00 It seems you are doing everything wrong. Your code example shows the class definition for ObjectA twice. Later you say you fill ObjectB with all its properties, but in the last code snippet it shows you are trying to map objectA to objectB, not the other way around.

– JoDG Mar 21 '11 at 8:17 @JoDG, My Mistake. I updated my initial post. Threw an exception of type 'System.Collections.Generic.

KeyNotFoundException' – user385411 Mar 21 '11 at 8:39 I have no idea where the exception comes from. Your actual question seems to be identical to this one however: stackoverflow.com/questions/3672447/how-... – JoDG Mar 21 '11 at 9:12 Yes, but it is very less complicated case How to update an existing object instance using AutoMapper? – user385411 Mar 21 '11 at 9:33.

I found the solution. I just discovered that Map method has an overloaded version that excepts a pre-instantiated destination object. Thanks to this article Mapper.

Map(objectA, ObjectB ); @JoDG, Thank you for your help.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions