简体   繁体   English

完整组满足条件的LINQ查询

[英]LINQ query where complete group meets a condition

I have stored a lot of text lines like this: 我存储了很多这样的文本行:

1|1000|1|0|Text Message|||
1|1000|1|1|Text Message|||
1|1000|2|0|Text Message|||
1|1000|2|1|Text Message|||
1|1000|3|0|Text Message|||
1|1001|1|0|Text Message|||

in a Collection: List<ObjRow> listRows 集合中的List<ObjRow> listRowsList<ObjRow> listRows

and this is the corresponding Class: 这是相应的类:

public class ObjRow
{
    private string n_Par { get; set; }
    private string n_Rad { get; set; }
    private string n_Lang { get; set; }
    private string n_Line_Mex { get; set; }
    private string text_Mex { get; set; } 
    private int n_Row { get; set; }
}

I would like to find which groups of lines (grouped by property n_Rad , 2° PIPE value) which have not the value n_Lang == 3 (3° PIPE value). 我想找到哪些线组(按属性n_Rad分组,2°PIPE值)不具有值n_Lang == 3 (3°PIPE值)。

How to do this with LINQ? 如何使用LINQ做到这一点?

This should be what you want: 这应该是您想要的:

var groupsWithoutLang3  = listRows
             .GroupBy(o => o.n_Rad)
             .Where(g => !g.Any(o => o.n_Lang == "3"));

It selects only groups without an ObjRow with n_Lang == "3" . 它仅选择不具有n_Lang == "3"ObjRow组。

var groups = listRows.GroupBy(row => row.Rad);
var result = groups.Where(group => !group.Any(item => (item.Lang == 3)));

This groups the rows by Rad and then selects the groups that do not contain a row whose Lang is 3. 这按Rad对行进行分组,然后选择不包含Lang为3的行的组。

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

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