首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

求问LinQ里distinct后的count如何写

2013-02-25 
求问LinQ里distinct后的count怎么写啊var a from x in listgroup x by x.postId into tselect new{t.Key

求问LinQ里distinct后的count怎么写啊
var a = from x in list
        group x by x.postId into t
        select new
        {
         t.Key,
         pv = t.Count(),
         uv = t.Distinct().Count()
        }
如这段代码所示,
我想要其实是pv和uv,pv不去重,uv要去重。
但是我用这个代码,好像distinct不管用啊。两个数是一样的。
是不是要在distinct里面加一个字段限制?怎么加求解。
[解决办法]
你按postId 分组了,Distinct和没有Distinct肯定是一样的
你除非在Distinct()里单独再处理

[解决办法]
var a = from x in list
        group x by x.postId into t
        select new
        {
         t.Key,
         pv = t.Count(),
         uv = t.Distinct(tt=>tt.XXX).Count()
        }
[解决办法]
uv = t.Distinct(a=>a.你要distinct的属性).Count();

热点排行