我正在尝试使用该AfterMap方法将输入类展平为输出。输入类如下所示:
public class FooDTO {
public string SomeFieldA { get; set; }
public string SomeFieldB { get; set; }
....
public BarDTO SomeFieldY { get; set; }
public BazDTO SomeFieldZ { get; set; }
}
public class BarDTO {
public string SomeOtherFieldA { get; set; }
}
public class BazDTO {
public string YetAnotherFieldA { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
和输出类如下:
public class Foo {
public string SomeFieldA { get; set; }
public string SomeFieldB { get; set; }
....
public string SomeOtherFieldA { get; set; }
public string YetAnotherFieldA { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的 AutoMapper 映射配置如下所示:
CreateMap<FooDTO, Foo>()
.AfterMap((src, dest, ctx) => ctx.Mapper.Map(src.SomeFieldY, dest))
.AfterMap((src, dest, ctx) => ctx.Mapper.Map(src.SomeFieldZ, dest));
CreateMap<BarDTO, Foo>();
CreateMap<BazDTO, Foo>();
Run Code Online (Sandbox Code Playgroud)
我的问题是,当我尝试运行应用程序时,出现以下未处理的异常:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.MissingMethodException: Method not found: 'AutoMapper.IMappingExpression`2<!0,!1> AutoMapper.IMappingExpression`2.AfterMap(System.Action`3<!0,!1,AutoMapper.ResolutionContext>)'.
Run Code Online (Sandbox Code Playgroud)
我是否缺少其他一些配置?如何让我的代码工作?
| 归档时间: |
|
| 查看次数: |
3529 次 |
| 最近记录: |