使用OData与Automapper和EF核心公开下面的数据模型,
- 客户
- CustomerMetric:CustomerLevel,VIPFlag,其他领域......
醇>
客户与CustomerMetric有一对多的关系。目标是让Customer控制器在CustomerMetric表的第一个匹配行中公开CustomerLevel,VIPFlag。
我在地图配置中做了什么,
- .ForMember(dest => dest.CustomerLevel,opt => opt.MapFrom(src => src.CustomerMetric.FirstOrDefault()。Level))
- .ForMember(dest => dest.VIPFlag,opt => opt.MapFrom(src => src.CustomerMetric.FirstOrDefault()。VIPFlag))
这一切都很好,正确填充了值。但是,automapper会触发对数据库的两次调用,并选择前1个CustomerLevel'另一个选择前1名VIPFlag'。
如何通过一次调用来获取两个字段而不是每个字段的两个调用?我试过。在控制器上包含它不起作用..
谢谢!