Search code examples
c#mappingautomapperautomapper-3

AutoMapper's Ignore() not working when using ForSourceMember?


I'm trying to ignore a property from source type. I have defined mapping like this:

var map = AutoMapper.Mapper.CreateMap<Article, IArticle>();
map.ForSourceMember(s => s.DateCreated, opt => opt.Ignore());
map.ForSourceMember(s => s.DateUpdated, opt => opt.Ignore());

When I call Map function,

AutoMapper.Mapper.Map(article, articlePoco);

destination's properties gets updated anyway. I'm using the latest stable version downloaded from NuGet.

Any ideas why this isn't working ?

I have found similar question to this one but there is no answer attached. [question]:AutoMapper's Ignore() not working?


Solution

  • Change the mapping to use ForMember:

    map.ForMember(s => s.DateCreated, opt => opt.Ignore());
    map.ForMember(s => s.DateUpdated, opt => opt.Ignore());