Question

I am using AutoMapper and try to update the properties of my existed objects from another object. Both objects are of same type. But it seems like when I use automapper on a existed object, it becomes a new object thus its reference is getting broken. So I have to do all this manually, Imagine if I have 100 properties on an object.

     originalWell.AngularLatitudeDegrees1 = updatedWell.AngularLatitudeDegrees1;
     originalWell.AngularLatitudeMinutes1 = updatedWell.AngularLatitudeMinutes1;
     originalWell.AngularLatitudeSeconds1 = updatedWell.AngularLatitudeSeconds1;
     originalWell.AngularLongitudDegrees1 = updatedWell.AngularLongitudDegrees1;
     originalWell.AngularLongitudMinutes1 = updatedWell.AngularLongitudMinutes1;
     originalWell.AngularLongitudSeconds1 = updatedWell.AngularLongitudSeconds1;

What I try is this

    AutoMapper.Mapper.CreateMap<Well,Well>();
    originalWell = AutoMapper.Mapper.Map<Well>(udpatedWell);
Was it helpful?

Solution

AutoMapper.Mapper.Map<Well, Well>(updatedWell, originalWell);

or in fact just:

AutoMapper.Mapper.Map(updatedWell, originalWell);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top