AutoMapper Wiki

less than 1 minute read



I am creating this post as a reference for myself and others that find it useful for things I found while using the AutoMapper library. I will continue to grow this list as reference page for tips, tricks, and best practices I’ve found.


This statement is one that I put on all of my mapping profiles to ensure that you don’t set values for properties that do not match your “From” object.

Mapper.CreateMap<FromObjectName, ToObjectName>()


I’ve seen some mapper profiles get very confused with the conditionals. This format helps keep it readable.

Mapper.CreateMap<FromObjectName, ToObjectName>()
    .ForMember(m => m.MyPropertyName, o =>
        o.Condition(s => s.MyPropertyToCheck == 1); 
        o.MapFrom(s => DoSomethingToProperty(s.MyPropertyName));