c# - 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; }
}
解决方案
推荐阅读
- python - 如何获取多输出模型的类激活图?
- python - 获取 www 子域或特定域的 cookie?
- ios - LineChartView chartViewDidEndPanning 和 chartValueNothingSelected 没有被调用,而 chartValueSelected 被完美调用
- javascript - 如何对 JSON 中的数组进行排序以获取特定索引的值?
- mysql - MySQL 说:Documentation-Subquery 返回多于 1 行
- javascript - 我的 Div 容器没有响应我所做的任何 CSS 更改
- google-sheets - 如何有条件地将谷歌表格中的一行复制到循环中的选项卡但不复制
- html - 如何为自定义浏览器新标签完成此 html 代码?
- sql - 'NVARCHAR' 附近的语法不正确
- latex - 怎样把人物放在背页的中间?