AutoMapper ignore attributes from mapping

This is an informative post because I was not able to find this information with above title and most of the time we try to search with this title phrase only.

When you are using AutoMapper and want to ignore some fields from the mapping then there is a simple solution provide from Automapper version 5.0 and later.

Mapper.Initialize(cfg =>
{
    cfg.CreateMap<Activity, ActivityListViewModel>(MemberList.Source);
});

above example is for the case when you want to validate all source properties and ignore destination properties.

If you want to do otherwise then a small change in above code should do just fine

Mapper.Initialize(cfg =>
{
    cfg.CreateMap<Activity, ActivityListViewModel>(MemberList.Destination);
});

And if you don’t want to validate source and destination both then simply use MemberList.None as parameter.

Mapper.Initialize(cfg =>
{
    cfg.CreateMap<Activity, ActivityListViewModel>(MemberList.None);
});

Only pending case other then above options is CreateMapp without parameters which is default and will validate source and destination both.