If I want to do bi-directional mapping, do I need to create two mapping?
Mapper.CreateMap<A, B>() and Mapper.CreateMap<B, A>()
?
What is AutoMapper Reverse Mapping in C#? The Automapper Reverse Mapping is nothing but the two-way mapping which is also called as bidirectional mapping.
Yes, or you can call CreateMap<ModelClass, ViewModelClass>(). ReverseMap() .
By calling ReverseMap , AutoMapper creates a reverse mapping configuration that includes unflattening: var customer = new Customer { Name = "Bob" }; var order = new Order { Customer = customer, Total = 15.8m }; var orderDto = mapper.
AutoMapper is a simple library that helps us to transform one object type into another. It is a convention-based object-to-object mapper that requires very little configuration. The object-to-object mapping works by transforming an input object of one type into an output object of a different type.
Yes, but if you find yourself doing this often:
public static class AutoMapperExtensions { public static void Bidirectional<TSource, TDestination>(this IMappingExpression<TSource, TDestination> expression) { Mapper.CreateMap<TDestination, TSource>(); } }
then:
Mapper.CreateMap<A, B>().Bidirectional();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With