Automapper在映射后给出null

时间:2017-04-04 17:09:40

标签: asp.net-mvc automapper asp.net-mvc-viewmodel

            var objInterview = ServiceManager.InterviewServiceInstance.GetInterview(InterviewID);
        Mapper.Initialize(cfg =>
        {
            cfg.CreateMap<Interview, InterviewViewModel>()
            .ForMember(dest => dest.CityName, opt => opt.MapFrom(src => src.Cities.CityName))
            .ForMember(dest => dest.DesignationName, opt => opt.MapFrom(src => src.Designations.DesignationName));
        });

        InterviewViewModel vmInterview = new InterviewViewModel();
        vmInterview = Mapper.Map<Interview, InterviewViewModel>(objInterview);
        return View("Interview", vmInterview);

objInterview具有CityID和DesignationID的值。但是在映射之后,我希望在vmInterview中获得CityName和DesignationName。我为他们取消了。我错过了什么吗?

0 个答案:

没有答案