如何在linq中基于group count对group by进行排序

如何在linq中基于group count对group by进行排序

问题描述:

如何获取分组上的列表并根据linq中包含的行数对分组列表进行排序。



我该怎么做。请帮助



我尝试过:



how get the list on group by and sort the grouped list based on containing row count in linq.

how can i do this. please help

What I have tried:

var add = attributeValue.OrderByDescending(x => x.AttributeID.Count()).GroupBy(x => x.AttributeID).ToList();

不确定您的数据是什么,但这可能是您正在寻找的:

Not sure what you data is but this may be what you are looking for:
var add = attributeValue.GroupBy(x => x.AttributeID)
                        .OrderByDescending((x) => x.Count());