我正在尝试将一个对象映射到另一个对象:
Mapper.CreateMap<ShippingAddressModel, ShippingAddress>()
.ForMember(x => x.Addresses.Name, opts => opts.MapFrom(x => x.Name));
但是我有一个错误:
表达式'x => x.Addresses.Name'必须解析为顶级成员而不是任何子对象的属性。请在子类型或AfterMap选项上使用自定义解析程序。
这应该工作:
Mapper.CreateMap<ShippingAddressModel, ShippingAddress>()
.ForMember(x => x.Addresses, opt => opt.MapFrom(model => model));
Mapper.CreateMap<ShippingAddressModel, Addresses>()
.ForMember(x => x.Name, opt => opt.MapFrom(model => model.Name));