惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
Recent Announcements
Recent Announcements
阮一峰的网络日志
阮一峰的网络日志
IT之家
IT之家
A
About on SuperTechFans
量子位
Engineering at Meta
Engineering at Meta
B
Blog
The Cloudflare Blog
博客园 - 【当耐特】
Hugging Face - Blog
Hugging Face - Blog
Y
Y Combinator Blog
J
Java Code Geeks
D
DataBreaches.Net
aimingoo的专栏
aimingoo的专栏
T
Tailwind CSS Blog
H
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
V2EX
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - 神游虚空

解决 GDAL 用 C# 访问时,中文乱码问题。 学习AI编程 安装 RAGFlow 安装 KTransformer 量化投资赚的哪方面的钱? python中调用 .net 的 dll 时,报错:Exception has occurred: TypeLoadException 使用 Open XML SDK 实现 html 富文本转换为 docx 格式示例 在python中 先调用C#的dll 返回了一个类的列表,如何把这个列表转换为 python 中的 DataFrame? vue项目服务器部属源码调试解决办法 vue3 + ts + element_plus 创建后台管理系统,学习记录 大A指数周内效应分析 两个通达信公式 如何在.netcore 上实现 Rbac 权限管理 修道是精神上的减熵过程 BPMN2.0 Specifaction 节选翻译,10.4.6 事件处理(handling Events,原文 275页) BPMN2.0 Specifaction 节选翻译,10.4 事件 Events (原文233页) 使用ef或dbcontext的时候主要注意三个问题 BPMN2.0 Specifaction 节选翻译,10.2.8 循环特征 Loop Characteristics (原文 189页) BPMN2.0 Specifaction 节选翻译,10.2.5 子流程 Sub-Processes (原文173页) BPMN2.0 Specifaction 节选翻译,10 Process (原文145页)
EFCore 中 group 分组后,只选出每组中含有最大值的数据行
神游虚空 · 2021-01-28 · via 博客园 - 神游虚空

一、背景

最近在 工作流项目 里使用 EFCore 遇到需要 group 分组后,只选出每组中含有最大值的数据行。

二、解决方案

先分组用 group 找到分组中的最大值,再用  join  查出对应的行。

var groupFlows = Context.Set<TInstanceFlow>().AsNoTracking()
            .GroupBy(f => f.ProcessInstanceId)
            .Select(g => new { instanceId = g.Key, finish = g.Max(f => f.Finish) });

var flows = Context.Set<TInstanceFlow>().AsNoTracking()
          .Join(groupFlows,
            o => new { f1 = o.ProcessInstanceId, f2 = o.Finish },
            i => new { f1 = i.instanceId, f2 = i.finish },
            (o, i) => new { o, i })
          .Select(g => new
          {
            Id = g.o.Id,
            ProcessInstanceId = g.i.instanceId,
            IsCanUndo = g.o.IsCanUndo,
          });

关键点是红色部分的键值对匹配。

三、参考资料

select-rows-with-maximum-value-on-a-column-in-sql-server

 join-query-in-ef-core/