开发者

Get the set of grouped values as a list using linq

开发者 https://www.devze.com 2023-01-08 06:05 出处:网络
I am taking a datatable and finding all the rows for a specific key that have fewer than three entries in the table for that key value. I can do this fine and it returns a grouping with the key b开发者

I am taking a datatable and finding all the rows for a specific key that have fewer than three entries in the table for that key value. I can do this fine and it returns a grouping with the key b开发者_运维问答eing the id I want to group on and a list of the datarows that, for each key value, don't exist at least three times. Now I want to get a straight list of all those datarows that failed. I am having trouble doing this. All I can seem to do is get a list of lists.

var rows = from dr in stagingTable.AsEnumerable()
group by dr.Field<long>("KEY_ID") into g
where g.Count() < 3
select new {ID = g.Key, Values = g};

Now that I have the grouped information, I want a straight list of all the datarows that can be found within all the groups. Doing g.ToList() just gives me a list of lists.

Any suggestions?


If you wanted to flatten that list of lists:

 var flattened = rows.SelectMany(x=>x.Values).ToList();
0

精彩评论

暂无评论...
验证码 换一张
取 消