1

We're using ViewModels based on a special class that has a few properties. These properties don't have mapping properties in the models. How can I tell AutoMapper to ignore these properties globally? This is what I tried but I still get errors related to these properties. Also, is there a way to pass multiple properties to be ignored in the CreateMap?

public class AutoMapperConfig
{
    public static MapperConfiguration mapperConfiguration = new MapperConfiguration(cfg =>
    {
          cfg.AddProfile(new MappingProfile());
          cfg.ShouldMapProperty = pi => !pi.Name.InList("HiddenSwitch","ErrorMessage",
                                   "SuccessMessage", "WarningMessage","DuplicateForm");
    });

   public static IMapper Mapper;

   public static void Configure()
   {
       Mapper = mapperConfiguration.CreateMapper();
       mapperConfiguration.AssertConfigurationIsValid();
   }
}
stuartd
  • 70,509
  • 14
  • 132
  • 163
Naomi
  • 718
  • 1
  • 9
  • 28
  • 1
    Possibly the answers here will help: http://stackoverflow.com/questions/954480/automapper-ignore-the-rest, not a duplicate, but definitely similar – Eris May 12 '16 at 22:40
  • 1
    Thanks, that was very helpful. I also found that I can use public static MapperConfiguration mapperConfiguration = new MapperConfiguration(cfg => { cfg.AddGlobalIgnore("HiddenSwitch"); cfg.AddGlobalIgnore("ErrorMessage"); cfg.AddGlobalIgnore("SuccessMessage"); cfg.AddGlobalIgnore("WarningMessage"); cfg.AddGlobalIgnore("DuplicateForm"); cfg.AddProfile(new MappingProfile()); }); – Naomi May 13 '16 at 04:05

0 Answers0