c# - LINQ finding the highest frequency -


i trying find "most popular" game based on number of occurrences. wrote linq query below

 var query = (from evt in events                         game in evt.eventgames                         group game game.gametypeid                         g                         select new {g.key, count = g.count()}).orderbydescending(x => x.count).firstordefault();   var gametype = repository.getrepository<gametype>().find(query?.key);  

i realised querying twice game type has highest frequency.

is possible game type first query itself?

-alan-

yes, group gametype instead of gametypeid.

var gametype = (from evt in events                 game in evt.eventgames                 group game game.gametype g                 orderby g.count() descending                 select g.key)                 .firstordefault(); 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -