从 Automapper 9.0 升级到 10.0 后,我开始收到System.ArgumentException:'Field 'AutomapperSandbox.Level2.TheField' is not defined for type 'AutomapperSandbox.Level1''
我的源对象是:
public class Level1
{
public Level2 FieldLevel2;
}
public class Level2
{
public long TheField;
}
public class Source
{
public string Id;
public Level1 FieldLevel1;
}
我的目标对象:
public class Destination
{
public string Id;
public long TheField;
}
映射:
var configuration = new MapperConfiguration(
cfg =>
{ cfg.CreateMap<Source, Destination>().IncludeMembers(s => s.FieldLevel1);
cfg.CreateMap<Level1, Destination>().IncludeMembers(s => s.FieldLevel2);
cfg.CreateMap<Level2, Destination>();
});
运行 mapper.Map<Source, Destination>(source) 时,会引发异常。我尝试了其他方法但没有成功。
这种行为是 Automapper 10.0 中引入的问题吗?我的代码有什么问题吗?
谢谢,
卡洛斯·马尔康