views:

156

answers:

2

If I want to do bi-directional mapping, do I need to create two mapping?

Mapper.CreateMap<A, B>() and Mapper.CreateMap<B, A>()?

+2  A: 

Yes, because if you change the type of some property (for example DateTime -> string) it is not bidirectional (you will need to instruct Automapper how to convert string -> DateTime).

Darin Dimitrov
+1  A: 

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();
Eric Hauser
thanks. it's cool
Benny