【发布时间】:2020-02-04 12:23:18
【问题描述】:
我正在使用 AutoMapper 9,我想映射我的嵌套表。在旧版本的 AutoMapper 中,我使用了这样的“CreateMap”:
CreateMap<Table, ViewModel>().AfterMap((s, d) => Mapper.Map(s.Table2, d)).ReverseMap();
我在下面找到了这个示例,但这仅适用于表格的一个元素。
CreateMap<Table, ViewModel>().ForMember(d=>d.Items,o=>o.MapFrom(s=>s.Table2.Items));
但在新版本 (Mapper.Map) 中无法正常工作,因为 AutoMapper 使用依赖注入。如何在新版本中简单地使用嵌套映射? 我没有隐瞒我想使用 AutoMapper 而不使用依赖注入。
【问题讨论】:
标签: c# asp.net-core automapper nested-table