C# “汽车制造商”;“未找到成员”;具有UseDestinationValue
我正在尝试使用AutoMapper将ViewModel映射到模型 以下是我的简化ViewModel(源)类: 以下是我的简化模型(目的地)类:C# “汽车制造商”;“未找到成员”;具有UseDestinationValue,c#,entity-framework,automapper-3,C#,Entity Framework,Automapper 3,我正在尝试使用AutoMapper将ViewModel映射到模型 以下是我的简化ViewModel(源)类: 以下是我的简化模型(目的地)类: 公共类付款点 { 公共Int64 Id{get;set;} 公共虚拟组织{get;set;} 公共虚拟雇主{get;set;} 公共虚拟列表EmploymentContracts{get;set;} 公共bool IsActive{get;set;} } 公营班级组织 { 公共Int64 Id{get;set;} 公共虚拟列表电子邮件地址{get;set
公共类付款点
{
公共Int64 Id{get;set;}
公共虚拟组织{get;set;}
公共虚拟雇主{get;set;}
公共虚拟列表EmploymentContracts{get;set;}
公共bool IsActive{get;set;}
}
公营班级组织
{
公共Int64 Id{get;set;}
公共虚拟列表电子邮件地址{get;set;}
公共虚拟列表联系人号码{get;set;}
公共虚拟列表地址{get;set;}
公共字符串注册表名{get;set;}
公共字符串TradingName{get;set;}
公共字符串注册号{get;set;}
公共字符串网站地址{get;set;}
}
以下是我执行的代码,用于在应用程序启动时在内存中创建映射:
Mapper.CreateMap<EditPaypointVM, Paypoint>()
.ForMember(dest => dest.IsActive,
opt => opt.UseValue(true))
.ForMember(dest => dest.Organisation,
opt => opt.UseDestinationValue())
.Ignore(i => i.Employer)
.Ignore(i => i.EmploymentContracts);
Mapper.CreateMap()
.ForMember(dest=>dest.IsActive,
opt=>opt.UseValue(true))
.FormMember(目标=>目标组织,
opt=>opt.UseDestinationValue())
.忽略(i=>i.雇主)
.忽略(i=>i.雇佣合同);
在单元测试中执行“AssertConfigurationsValid”时,将抛出一个“未映射错误”,表示Paypoint的组织成员未映射
关于导致这种情况的原因有什么想法吗?组织的类型是什么??顺便说一句,为了使资产配置有效,您需要使用
忽略您的属性。忽略(i=>i.organization)
或者您需要编写:.formmember(dest=>dest.organization,opt=>{opt.MapFrom(src=>src.organization);opt.UseDestinationValue();});
使资产配置有效
happy@nemesvOrganization是一种复杂类型,包含地址等其他复杂类型的集合。需要设置Organization的一些内部属性,这就是我应用“UseDestinationValue”的原因。@nemesv源类,EditPaypointVM
已被禁用它只包含映射到组织属性的属性。因此.ForMember(dest=>dest.organization,opt=>{opt.MapFrom(src=>src.organization);opt.usedstinationvalue();})
不会编译.ForMember(dest=>dest.organization,opt=>{opt.MapFrom(src=>src.organization);opt.UseDestinationValue();});
应编译…错误消息是什么?您使用的是哪个版本的Automapper?
public class Paypoint
{
public Int64 Id { get; set; }
public virtual Organisation Organisation { get; set; }
public virtual Employer Employer { get; set; }
public virtual List<EmploymentContract> EmploymentContracts { get; set; }
public bool IsActive { get; set; }
}
public class Organisation
{
public Int64 Id { get; set; }
public virtual List<EmailAddress> EmailAdresses { get; set; }
public virtual List<ContactNumber> ContactNumbers { get; set; }
public virtual List<Address> Adresses { get; set; }
public string RegisteredName { get; set; }
public string TradingName { get; set; }
public string RegistrationNumber { get; set; }
public string WebsiteAddress { get; set; }
}
Mapper.CreateMap<EditPaypointVM, Paypoint>()
.ForMember(dest => dest.IsActive,
opt => opt.UseValue(true))
.ForMember(dest => dest.Organisation,
opt => opt.UseDestinationValue())
.Ignore(i => i.Employer)
.Ignore(i => i.EmploymentContracts);