首页 > 解决方案 > 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);

标签: c#.netautomapper

解决方案


推荐阅读