1

考虑 :

class OriginalContact
{
    public int Id{set;get;}
    public string Name{set;get;}
    public string CustomerCode{set;get;}
}

class DTOContact
{
    public int Id{set;get;}
    public string Name{set;get;}
}

OriginalContact originalContact = new OriginalContact
{
    CustomerCode="123";
}

DTOContact dtoContact= new DTOContact
{
    Id=1,
    Name="David"
}

Mapper.Map(dtoContact, originalContact);

在这个映射之后,我失去了CustomerCode

有没有办法在保持原始值的同时进行映射?

4

1 回答 1

1

您应该能够在创建地图配置中“忽略”目标值:

Mapper.CreateMap<DTOContact,OriginalContact>()
  .ForMember(dest => dest.CustomerCode, options => options.Ignore());
于 2012-11-29T09:13:26.737 回答