Previously, when I used Automapper v3.x, ignoring unlabeled properties could be done simply by adding the .IgnoreUnmappedProperties() extension, which looked like this:
public static class AutoMapperExtensions { public static IMappingExpression<TSource, TDestination> IgnoreUnmappedProperties<TSource, TDestination>(this IMappingExpression<TSource, TDestination> expression) { var typeMap = Mapper.FindTypeMapFor<TSource, TDestination>(); if (typeMap != null) { foreach (var unmappedPropertyName in typeMap.GetUnmappedPropertyNames()) { expression.ForMember(unmappedPropertyName, opt => opt.Ignore()); } } return expression; } }
How this extension can be rewritten to work with version 5.x. Of course, I can add the following to each property.
.ForMember(dest => dest.LastUpdatedBy, opt => opt.Ignore())
or not cause
Mapper.AssertConfigurationIsValid();
source share