繁体   English   中英

A类型的自动映射器将源属性映射到目标列表

[英]Automapper map source property of type A to destination List<B>

我的问题是我既需要将类型A转换为类型B(以及所有嵌套类型!) ,还需要同时将单个对象('A')转换为对象列表 ('B')。

public class SourcePoco
{
    public ComplexTypeA MyProblem { get; set; }
    // there be more properties...
}

public class ComplexTypeA
{
    // ...more nested complex types
}

现在我的问题是如何将MyProblem映射到以下目标类型:

public class DestinationPoco
{
    public IEnumerable<ComplexTypeB> MyProblems { get; set; }
    // there be more properties...
}

我确实有以下映射:

CreateMap<SourcePoco, DestinationPoco>()
   .ForMember(...);

CreateMap<ComplexTypeA , ComplexTypeB>()
   .ForMember(dest => dest.Id, opt => opt.Ignore());

CreateMap<ComplexTypeA, IEnumerable<ComplexTypeB>>()
    .ConvertUsing<MyProblemConverter>();

我尝试添加类似的内容-但从未被调用。

卸下该转换器。 试一下

CreateMap<SourcePoco, DestinationPoco>().ForMember(d=>MyProblems,o=>o.MapFrom(s=>new[]{s.MyProblem}));

暂无
暂无

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

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