AutoMapper bidirectional mapping

前端 未结 4 1115
耶瑟儿~
耶瑟儿~ 2020-12-28 14:05

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

Mapper.CreateMap() and Mapper.CreateMap()?

4条回答
  •  鱼传尺愫
    2020-12-28 14:51

    Great idea Eric! I've added a return value, so the reverse mapping is configurable too.

    public static class AutoMapperExtensions
    {
        public static IMappingExpression Bidirectional(this IMappingExpression expression)
        {
            return Mapper.CreateMap();
        }
    }
    

提交回复
热议问题