选择使用LINQ最频繁的价值 [英] Select most frequent value using LINQ
本文介绍了选择使用LINQ最频繁的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的表中选择的五大最频繁的值,并在列表中返回他们。
VAR mostFollowedQuestions =(从●在context.UserIsFollowingQuestion
从q.QuestionId *前五名发生的历史价值) .toList();
任何想法?
感谢
解决方案
VAR mostFollowedQuestions = context.UserIsFollowingQuestion
.GroupBy(q =>问.QuestionId)
.OrderByDescending(GP = GT; gp.Count())
。取(5)
。选择(G => g.Key).ToList();
I'm trying to select the top five most frequent values in my table and return them in a List.
var mostFollowedQuestions = (from q in context.UserIsFollowingQuestion
select *top five occuring values from q.QuestionId*).toList();
Any idea?
Thanks
解决方案
var mostFollowedQuestions = context.UserIsFollowingQuestion
.GroupBy(q => q.QuestionId)
.OrderByDescending(gp => gp.Count())
.Take(5)
.Select(g => g.Key).ToList();
这篇关于选择使用LINQ最频繁的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文