c# - 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;
解决方案
推荐阅读
- javascript - if 语句不返回任何 TRUE,即使它应该
- java - 从片段调用活动使用接口,但为什么?
- kubernetes-ingress - 同一后端服务中多个路径的 K8s Ingress 规则
- excel - 如何通过从单元格中获取形状名称来引用形状?
- android - Gradle 错误无法解析 com.github.Binary-Finery:Bungee:master-SNAPSHOT
- c# - 将带有计数的嵌套 SQL 转换为 linQ
- sql - 您如何根据记录总数计算具有统计意义的样本量?(Postgres)
- javascript - 需要以不同的方式格式化对象数组
- java - 带有可选按钮的密码字段以使用 vaadin 显示密码
- python - 使用 Python(正则表达式)将数据仅放在数据框中的方括号中