AutoMapper bidirectional mapping

前端 未结 4 1094
耶瑟儿~
耶瑟儿~ 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:55

    Yes, but if you find yourself doing this often:

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

    then:

    Mapper.CreateMap().Bidirectional();
    

提交回复
热议问题