首页 > 解决方案 > Automapper 未将列表 dto 映射到列表

问题描述

这种性质的一个有趣的问题。我正在尝试将列表映射到列表。即比较两个同质对象。但是,映射器向我抛出了一个异常

缺少类型映射配置或不支持的映射。

如果有任何帮助,我将不胜感激!我一整天都解决不了问题。

   CreateMap<List<GrammarQuestionDTO>, TestDTO>()
        .ForMember(t => t.GrammarQuestion, map => map.MapFrom(source => source))
        .ForAllOtherMembers(x => x.Ignore());


public class GrammarQuestionDTO
{
    public int Id { get; set; }

    public LevelType LevelType { get; set; }

    public QuestionType QuestionType { get; set; } = QuestionType.Grammar;

    public string Question { get; set; }

    public List<AnswerDTO> Answers { get; set; }
}

public class TestDTO
{
    public int Id { get; set; }

    public List<GrammarQuestionDTO> GrammarQuestion { get; set; }

    public List<AuditionQuestionDTO> AuditionQuestion { get; set; }

    public string EssayTopic { get; set; }

    public string SpeakingTopic { get; set; }
}

标签: c#asp.net.netautomapper

解决方案


推荐阅读