我有以下对象:
public class DomainStudent {
public long Id { get; set; }
public string AdvisorId { get; set; }
}
public class ApiStudent {
public long Id { get; set; }
public long AdvisorName { get; set; }
}
当我运行以下映射时:
ApiStudent api = new ApiStudent();
api.Id = 123;
api.AdvisorName = "Homer Simpson";
DomainStudent existing = service.load(api.Id); // 123
// at this point existing.AdvisorId = 555
existing = Mapper.Map<ApiStudent, DomainStudent>(api);
// at this point existing.AdvisorId = null
如何配置 AutoMapper,以便当AdvisorId
源对象中缺少该属性时,它不会被覆盖为 null?