2

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

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).

How to do this with LINQ?

4

2 回答 2

3

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".

于 2013-05-15T13:10:32.660 回答
1
var groups = listRows.GroupBy(row => row.Rad);
var result = groups.Where(group => !group.Any(item => (item.Lang == 3)));

这会将行Rad分组,然后选择不包含Lang为 3 的行的组。

于 2013-05-15T13:09:20.943 回答