我有以下Dto和实体与嵌套的子实体.
public class Dto
{
public string Property { get; set; }
public string SubProperty { get; set; }
}
public class Entity
{
public string Property { get; set; }
public SubEntity Sub { get; set; }
}
public class SubEntity
{
public string SubProperty { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
如何使用AutoMapper设置映射,这将允许我使用Dto中的值更新现有的Entity实例.
我正在使用Mapper.Map(dto, entity)更新现有实体但是当我尝试映射Dto.SubProperty到时,Entity.Sub.SubProperty我得到一个例外,"必须解析为顶级成员.参数名称:lambdaExpression".
如果我从创建一个映射Dto到SubEntity使用FromMember,然后Entity.Sub被用的新实例所取代SubEntity,但是这不是我想要的.我只是想让它更新属性的现有实例SubEntity …