Skip to main content

A couple useful AutoMapper extension methods of ignoring some, or all properties.

// A more elegant auto-mapper ignore
public static IMappingExpression<TSource, TDestination> Ignore<TSource, TDestination>(
    this IMappingExpression<TSource, TDestination> map,
    Expression<Func<TDestination, object>> selector)
    map.ForMember(selector, config => config.Ignore());
    return map;

// Usage:
Mapper.CreateMap<JsonRecord, DatabaseRecord>()
    .Ignore(record => record.Field)
    .Ignore(record => record.AnotherField)
    .Ignore(record => record.Etc);

// See for an IgnoreUnmappedProperties extension