c# - Automapper 错误 System.ArgumentException 映射子实体
问题描述
对不起,我的主要语言不是英语。我有使用 AutoMapper 映射的类,这些类以前工作但停止工作,现在显示错误异常System.ArgumentException: 'Property 'System.String OtherSubName' is not defined for type
public class EntityFrom
{
public string Name { get; set; }
public SubEntityFrom SubEntityFrom { get; set; }
}
public class SubEntityFrom
{
public string SubName { get; set; }
public OtherSubEntityFrom OtherSubEntityFrom { get; set; }
}
public class OtherSubEntityFrom
{
public string OtherSubName { get; set; }
}
public class EntityTarget
{
public string Name { get; set; }
public string SubName { get; set; }
public string OtherSubName { get; set; }
}
我像这样配置映射:
cfg.CreateMap<OtherSubEntityFrom, EntityTarget>();
cfg.CreateMap<SubEntityFrom, EntityTarget>()
.IncludeMembers(x => x.OtherSubEntityFrom);
cfg.CreateMap<EntityFrom, EntityTarget>()
.IncludeMembers(x => x.SubEntityFrom);
解决方案
推荐阅读
- python - 使用python中的api将图像从驱动器插入幻灯片
- c# - Revit插件,启动时重置表单的所有值
- android - Google Play 管理中心 - 如何通知我的应用是否包含广告
- java - 如何在 `@Query` 注释的存储库方法中启用通用返回类型?
- css - 如何删除工具提示箭头边框
- flutter - 如何在颤振可搜索下拉列表中从 api 列表中搜索数据
- python - Django ForeignKey 哪个字段?
- kotlin - 函数必须接受另一个函数的结果作为参数 Kotlin
- elasticsearch - Elasticsearch 停用词相对路径
- mysql - “#1265 - 数据被截断”错误更改列(集)值