繁体   English   中英

当我使用 AutoMapper 时,如果这些属性具有相同的名称,我是否需要明确地编写所有属性?

[英]Do I need to write all the properties explicitly when I am using AutoMapper, if these properties have the same name?

我一直在尝试这样做,但是当我调试测试时,对象返回 null。 我想做复杂的对象到对象映射,但我无法让它工作。

代替:

cfg.CreateMap<Payments, Customer.Payments>()
    .ForMember(to => to.SomeName, opts => opts.MapFrom(from => from.SomeName))
    .ForMember(to => to.SomeDate, opts => opts.MapFrom(from => from.SomeDate));

我们想做:

    cfg.CreateMap<Payments, Customer.Payments>();

如果您还没有,我肯定会查看他们的Wiki

根据您上面的评论,您似乎对mapper.map的签名感到困惑。

这是你可以做的: var dest = mapper.Map<Dest>(new Source());

根据您发布的代码查看这个简单的小提琴以获得一个工作示例。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM