AutoMapper 9映射嵌套表

问题描述 投票:0回答:1

我正在使用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
1个回答
1
投票
最后我找到了解决方案。对某人可能有用:
© www.soinside.com 2019 - 2024. All rights reserved.