Try updating the nuget package.
This was fixed in issue #310. The first version to implement the change is 3.0.0.
문제
Here is a small code snippet that illustrate the problem.
[TestMethod]
public void AutoMapper_MappingNullValue_ShouldMapNull()
{
//Arrange
var source = new DummySource { MyDate = null };
var destination = new DummyDestination { MyDate = DateTime.Now };
AutoMapper.Mapper.CreateMap<DummySource, DummyDestination>();
//Act
var returnResult = AutoMapper.Mapper.Map(source, destination);
//Assert
Assert.IsNull(returnResult.MyDate);
Assert.IsNotNull(destination.MyDate);
}
private class DummySource
{
public DateTime? MyDate { get; set; }
}
private class DummyDestination
{
public DateTime? MyDate { get; set; }
}
How come this fail on the first assert? I expected to have a null value on the result. In fact, returnResult
and destination
are both with their initial value.
해결책
Try updating the nuget package.
This was fixed in issue #310. The first version to implement the change is 3.0.0.