Linq集团。关键字段数

时间:2013-02-19 17:27:55

标签: linq linq-to-sql

select    
  count(di.field1) as myCount,
  di.field2
  from di
group by  di.field2

我试图理解这个概念:

 group di.field2 by new { di.field1, di.field2 } into g
       select new
          {
             documentID = g.Key.field2,
             docCount = g.Count(????)
          });

我如何获得field1计数的值?

3 个答案:

答案 0 :(得分:1)

也许是这样的:

group di by di.field2 into g
       select new
          {
             documentID = g.Key,
             docCount = g.Select(c => c.field1).Count()
          });

答案 1 :(得分:1)

    from p in di
    group p by p.field2 into g 
    select new { field2 = g.Key, field2Count = g.Count() };

检查一下。,这应该可行

答案 2 :(得分:0)

您是否需要进行分组才能获得字段数?你不能这样做:

var count=di.field1.Count;