Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# LINQ表达式,用于按字符串属性选择对象,其队列属性中对象的最大计数不重复_C#_Linq - Fatal编程技术网

C# LINQ表达式,用于按字符串属性选择对象,其队列属性中对象的最大计数不重复

C# LINQ表达式,用于按字符串属性选择对象,其队列属性中对象的最大计数不重复,c#,linq,C#,Linq,我有一个记录对象队列,如下所示: public class Record { public string TypeDesc { get; set; } public Queue<Total> Totals { get; set; } etc..... } 公共类记录 { 公共字符串TypeDesc{get;set;} 公共队列总数{get;set;} 等 } 我在编写LINQ表达式来提取一个子集时遇到了问题,该子集中

我有一个记录对象队列,如下所示:

     public class Record
     {
     public string TypeDesc { get; set; }

     public Queue<Total> Totals { get; set; }

     etc.....
     }
公共类记录
{
公共字符串TypeDesc{get;set;}
公共队列总数{get;set;}
等
}
我在编写LINQ表达式来提取一个子集时遇到了问题,该子集中只有每个TypeDesc中的一个,但在每个TypeDesc中,有一个在Totals队列中包含最多对象

我不确定这是否重要,但只有一个TypeDesc在Totals队列属性中包含Total对象。队列中的所有其他人都是空的。大约有8个唯一的TypeDesc值

这是我的尝试,但totals属性在“s”上不可用

var records=records.Select(c=>c.TypeDesc).Where(s=>s.Totals.Count).Max().Distinct()

  • 按记录的
    TypeDesc
    属性对记录进行分组
  • 对于每个组,选择总数最高的组。计数

  • records.GroupBy(r => r.TypeDesc)
           .Select(
                g => g.Aggregate((acc, current) => current.Totals.Count > acc.Totals.Count
                                                        ? current
                                                        : acc));
    
    对于这样的复杂查询,最好将逻辑分解一点,以使代码更具可读性:

    Func<IEnumerable<Record>, Record> mostTotals =
        group => group.Aggregate(
            (acc, current) => current.Totals.Count > acc.Totals.Count
                                  ? current
                                  : acc);
    
    var records = records.GroupBy(r => r.TypeDesc)
                         .Select(mostTotals);
    
  • 按记录的
    TypeDesc
    属性对记录进行分组
  • 对于每个组,选择总数最高的组。计数

  • records.GroupBy(r => r.TypeDesc)
           .Select(
                g => g.Aggregate((acc, current) => current.Totals.Count > acc.Totals.Count
                                                        ? current
                                                        : acc));
    
    对于这样的复杂查询,最好将逻辑分解一点,以使代码更具可读性:

    Func<IEnumerable<Record>, Record> mostTotals =
        group => group.Aggregate(
            (acc, current) => current.Totals.Count > acc.Totals.Count
                                  ? current
                                  : acc);
    
    var records = records.GroupBy(r => r.TypeDesc)
                         .Select(mostTotals);
    
  • 按记录的
    TypeDesc
    属性对记录进行分组
  • 对于每个组,选择总数最高的组。计数

  • records.GroupBy(r => r.TypeDesc)
           .Select(
                g => g.Aggregate((acc, current) => current.Totals.Count > acc.Totals.Count
                                                        ? current
                                                        : acc));
    
    对于这样的复杂查询,最好将逻辑分解一点,以使代码更具可读性:

    Func<IEnumerable<Record>, Record> mostTotals =
        group => group.Aggregate(
            (acc, current) => current.Totals.Count > acc.Totals.Count
                                  ? current
                                  : acc);
    
    var records = records.GroupBy(r => r.TypeDesc)
                         .Select(mostTotals);
    
  • 按记录的
    TypeDesc
    属性对记录进行分组
  • 对于每个组,选择总数最高的组。计数

  • records.GroupBy(r => r.TypeDesc)
           .Select(
                g => g.Aggregate((acc, current) => current.Totals.Count > acc.Totals.Count
                                                        ? current
                                                        : acc));
    
    对于这样的复杂查询,最好将逻辑分解一点,以使代码更具可读性:

    Func<IEnumerable<Record>, Record> mostTotals =
        group => group.Aggregate(
            (acc, current) => current.Totals.Count > acc.Totals.Count
                                  ? current
                                  : acc);
    
    var records = records.GroupBy(r => r.TypeDesc)
                         .Select(mostTotals);