Doing a copy of the same entity type in an MVC app, but looking to ignore copying the primary key (doing an update to an existing entity). But setting the Id column to ignore in the map below is not working and the Id is being overwritten.
cfg.CreateMap<VendorContact, VendorContact>()
.ForMember(dest => dest.Id, option => option.Ignore())
.ForMember(dest => dest.CreatedById, option => option.Ignore())
.ForMember(dest => dest.CreatedOn, option => option.Ignore())
;
Executing the Map:
existingStratusVendorContact = Mapper.Map<VendorContact>(vendorContact);
Saw this other answer, but it appears I am doing that already.
UPDATE:
Fyi, I am creating my maps in the Global.asax like so:
Mapper.Initialize(cfg =>
{
cfg.CreateMap<VendorContact, VendorContact>()
.ForMember(dest => dest.Id, option => option.Ignore())
.ForMember(dest => dest.CreatedById, option => option.Ignore())
.ForMember(dest => dest.CreatedOn, option => option.Ignore())
;
});
existingStratusVendorContact
is an existing object and you want to replace properties exceptId
,CreatedById
,CreatedOn
? or create a new one with this properties in default value?