2
我正在使用這種Using DynamicMap() and ignore null source value方法使映射器忽略來源上具有NULL值的屬性,但這似乎不適用於版本2.1.267.0(當前)。AutoMapper IsSourceValueNull條件不起作用
這裏是我的映射配置:
Mapper.CreateMap<PersonDTO, Person>().ForAllMembers(
opt => opt.Condition(srs => !srs.IsSourceValueNull));
這裏是我的測試:
// Arrange
var Person = new Person { FirstName = "Bruce", Surname = "Lee"};
var PersonDto = new PersonDTO { FirstName = "Jet", Surname = null };
// Act
Mapper.Map(PersonDto, Person);
// Assert
Assert.AreEqual("Jet", Person.FirstName); // Assert.AreEqual failed. Expected:<Jet>. Actual:<Bruce>.
Assert.AreEqual("Lee", Person.Surname, "Surname field with NULL value should not have been mapped");
它是否適合你?如果是這樣,你能在我的代碼中發現問題嗎?