entity-framework - 分组时,如何选择除 key 和 agregates 以外的列
问题描述
什么是 LINQ 等价物
SELECT primaryID, name, description, unit, SUM(price)
FROM Product
JOIN so that same Products are returned multiple times
GROUP BY primaryID
我知道可以使用 LINQ 进行 groupBy 查询,如下所示:
(from item in dbContext.products
join some join statement that will make products return multiple times
group item by item.primaryID into g
select new {id = key, summedPrice = g.Sum(x => x.price)}
)
但是这样,我只能得到 ID 和聚合。我如何获得其他领域?
我想我可以让我的密钥成为一个包含我需要的所有列的 annon 类,但我注意到这是否会影响性能,如下所示:
group item by new { item.primaryID, item.name, item.description...} into g
解决方案
推荐阅读
- azure - 在 Azure 中运行服务而不管理 VM
- email - 通过 mailto 链接自定义标题
- javascript - Angular Material - 仅当条件为真时才在鼠标悬停时显示 Mat-Menu
- javascript - 动态 Webpack 需要文件夹中的内容
- xdebug - 使用 Xdebug 的捆绑调试客户端,示例说明如何在单步执行页面时同时设置局部变量和全局变量
- php - UPDATE查询php语法
- node.js - 如何在为 Nestjs 上的静态 index.html 文件提供服务的根路由上调用中间件?
- node.js - 我可以在 Typegoose 中使用私有属性吗?
- oracle - 在 Oracle Database 11g XE 中,如何从已删除工作区的应用程序构建器中删除应用程序?
- python - 尝试在 Amazon AWS 实例上安装 keras 和 tensorflow