代码之家  ›  专栏  ›  技术社区  ›  Luke101

如何获取linq group by子句中的所有select键

  •  0
  • Luke101  · 技术社区  · 16 年前

    我正在尝试获取此Linq查询中的其余选择键,但IntelliSense给了我一个错误

    var query2 = from row2 in query1
                         group row2 by row2.questionid into g
                         where g.Count() > 0
                         select new
                         {
                             questionid1,   //Error here
                             time,          //Error here
                             thecount = g.Count()
                         };
    

    如何获得这些选择键?

    2 回复  |  直到 16 年前
        1
  •  6
  •   Yannick Motton    16 年前

    questionid time

    var query2 = from row2 in query1
                 group row2 by new { row2.questionid, row2.time } into g
    //           where g.Count() > 0
                 select new
                 {
                     g.Key.questionid,
                     g.Key.time,
                     thecount = g.Count()
                 };
    
        2
  •  0
  •   Jon Skeet    16 年前

    questionid questionid1

    Key g.Count()

    where