How to configure Conditional Mapping in AutoMapper in C# and VB.NET

To configure Conditional Mapping in AutoMapper in C# and VB.NET you can use the following snippet.

Sample C#

 Mapper.CreateMap<Source, Target>().ForMember(dest => dest.Value, opt => opt.MapFrom(src => src.Variable1 == "Value1" ? true : false));

Sample VB.NET

Mapper.CreateMap(Of Source, Target)().ForMember(Function(dest) dest.Value, Function(opt) opt.MapFrom(Function(src) If(src.Variable1 = "Value1", True, False)))

One thought on “How to configure Conditional Mapping in AutoMapper in C# and VB.NET

Leave a Reply