首页 > 解决方案 > Automapper 多个投影

问题描述

是否可以使用自动映射器的投影更新现有对象?更具体地说,我有多个数据库 (efcore) 实体,我想将其中的一部分组合起来,以便创建一个通过我们的 API 公开的新模型。我想使用投影,因为它会根据我的映射生成有效的查询,因为我不需要来自每个实体的所有数据,只需要一个子集。

var apiDto = await _context.Records
    .Where(x => x.Id == recordId)
    .ProjectTo<ApiModel>(_mapper.ConfigurationProvider)
    .SingleOrDefaultAsync();
// Here I want to map more data from a different entity into apiDto using another projection
return apiDto;

标签: c#asp.net-coreentity-framework-coreautomapper

解决方案


推荐阅读