목표는 원본 개체가 대상 개체의 모든 필드를 가질 필요없이 null 원본 값을 무시하는 것입니다. 모든 필드가 객체간에 일치하는 경우에만 null을 방지하는 것으로 보인다.모든 원본 속성이 일치하지 않는 경우 AutoMapper가 null 소스 값을 방지 할 수 없음
public class ApiStudent {
public long Id { get; set; }
public string Name { get; set; }
}
public class DomainStudent {
public long Id { get; set; }
public string Name { get; set; }
public long SchoolId { get; set; }
}
나는 다음과 같은 매핑을 실행하는 경우 :
Mapper.CreateMap<ApiStudent, DomainStudent>()
.ForAllMembers(opt => opt.Condition(src => !src.IsSourceValueNull));
var api = new ApiStudent();
api.Id = 123;
api.Name = null;
var domain = new DomainStudent();
domain.Id = 123;
domain.Name = "Homer Simpson"; // goal is to prevent this from being written to null
domain = Mapper.Map(api, domain);
// I get an error here saying the SchoolId mapping is missing from ApiStudent
을 나는 제거하면 ".ForAllMembers를 (! 옵트 => opt.Condition (SRC => src.IsSourceValueNull));" 매핑 정의에서 오류가 발생하지 않지만 .Name 속성이 null로 덮어 쓰여집니다. AutoMapper가 원본 개체가 아닌 대상 개체에있는 속성을 건너 뛰게하려면 여기에 무엇을 놓치셨습니까?
내가 뭘 찾고 있었는지 고마워. – Brendan