AutoMapper's Ignore() not working when using ForSourceMember?
Change the mapping to use ForMember:
map.ForMember(s => s.DateCreated, opt => opt.Ignore());
map.ForMember(s => s.DateUpdated, opt => opt.Ignore());
If the property that you want to ignore only exists in the source object then you can you MemberList.Source
in combination with the option method DoNotValidate()
. See below:
CreateMap<IArticle, Article>(MemberList.Source)
map.ForSourceMember(src => src.DateCreated, opt=> opt.DoNotValidate());
map.ForSourceMember(src => src.DateUpdated, opt => opt.DoNotValidate());
This is perfect if you are using AssertConfigurationIsValid
and want to ignore validation of certain source properties.