导航属性映射

时间:2018-03-12 13:16:04

标签: c# asp.net-mvc visual-studio entity-framework-6 automapper

我想映射属性导航。 我的情况:> 我有一个“清单”类

public class Listing {
        public int OfficeId {get;set;}
        public int PropertyCountryId { get; set; }
        public string PropertyPostalCode { get; set; }
}

和“ListingViewModel”

public class ListingViewModel
    {
        public LocationViewModel Location { get; set; }
        public int OfficeId { get; set; }       
    }

我需要将“PropertyCountryId”和“PropertyPostalCode”从“Listing”映射到我的ViewModel“LocationViewModel”。 自动配置:

CreateMap<Listing, ListingViewModel>()
 .ForMember(dest => dest.Location, map => map.MapFrom(
                source => new Location
                {
                    PropertyCountryId= source.PropertyCountryId,
                    PropertyPostalCode= source.PropertyPostalCode,
                }
                ));

错误消息:

  

找到未映射的成员。查看下面的类型和成员。   添加自定义映射表达式,忽略,添加自定义解析程序或修改源/目标类型   对于没有匹配的构造函数,添加一个no-arg ctor,添加可选参数或映射所有构造函数参数

0 个答案:

没有答案
相关问题