Ignore a property in AutoMapper?
I use this extension method:
public static IMappingExpression<TSource, TDestination> IgnoreMember<TSource, TDestination>(
this IMappingExpression<TSource, TDestination> map, Expression<Func<TDestination, object>> selector)
{
map.ForMember(selector, config => config.Ignore());
return map;
}
and I use it like this
Mapper.CreateMap<MyType1, MyType2>().IgnoreMember(m => m.PropertyName);
Hope that helps.
On your Mapper.CreateMap<Type1, Type2>()
you can use either
.ForSourceMember(x => x.Id, opt => opt.Ignore())
or
.ForMember(x => x.Id, opt => opt.Ignore())
UPDATE:
It seems like .Ignore()
is renamed to .DoNotValidate()
according to the AutoMapper docs.