【问题标题】:How to select the most repeating records in related tables with Entity Framework如何使用实体框架选择相关表中重复次数最多的记录
【发布时间】:2022-08-18 21:49:06
【问题描述】:

我的桌子在这里:

在 C# 中

我想知道博客表中重复次数最多的 3 个 categoryName 及其计数,知道吗?谢谢

    标签: c# asp.net-mvc asp.net-core asp.net-core-mvc


    【解决方案1】:
    list.GroupBy(x => x.CategoryName).Select(x => new { x.Key, count = x.Count() }).OrderBy(x => x.count).Take(3).Select(x => x.Key);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 2012-10-17
      • 1970-01-01
      • 2012-02-19
      • 1970-01-01
      相关资源
      最近更新 更多