简体   繁体   English

在IEnumerable结果中使用分组

[英]using group by in IEnumerable result

I have a query like below : 我有如下查询:

 IEnumerable<qryTable1> templates = from t in db.qryTable1
                                           where (t.GID == 1&&
                                           t.RID == 4 && t.CID == "user")
                                           select t;

Let say, Above query returns following result: 假设,上述查询返回以下结果:

TId GId RId CID
1    1   1   a
1    1   2   a
2    1   1   a
2    1   2   a
3    1   1   a
3    1   2   a

Now I want to get result from the above query like below:(removing RId column so that result have duplicate entries having only TId,GId,CID and then group the result by TId). 现在我想从上述查询中获取结果,如下所示:(删除RId列,以便结果具有仅具有TId,GId,CID的重复条目,然后按TId分组结果)。

TId GId  CID
1    1    a
2    1    a
3    1    a

Also , I want to get the desired output in template object only.It means result should be in ' IEnumerable<qryTable1> ' object. 另外,我只想在模板对象中获得所需的输出。这意味着结果应该在IEnumerable<qryTable1>对象中。

var distinct = db.qryTable1.Select(r => new {Tid = r.TId, GId = r.GId, CId = r.CId})
    .Distinct();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM