Automapper expression must resolve to top-level member

前端 未结 5 979
感情败类
感情败类 2020-12-06 09:29

I am using automapper to map source and destination objects. While I map them I get the below error.

Expression must resolve to top-level member. Par

5条回答
  •  长情又很酷
    2020-12-06 09:58

    The correct answer given by allrameest on this question should help: AutoMapper - Deep level mapping

    This is what you need:

    Mapper.CreateMap()
        .ForMember(dest => dest.OutputData, opt => opt.MapFrom(i => i));
    Mapper.CreateMap()
        .ForMember(dest => dest.Cars, opt => opt.MapFrom(i => i.Cars));
    

    When using the mapper, use:

    var destinationObj = Mapper.Map(sourceObj)
    

    where destinationObj is an instance of Destination and sourceObj is an instance of Source.

    NOTE: You should try to move away from using Mapper.CreateMap at this point, it is obsolete and will be unsupported soon.

提交回复
热议问题