0

I have a database like this which i would like to get the top 10 country ranking with ties with linq to entities. We can use index to solve the ranking problem if tie ranking is omitted. However, what i needed here is to query tie ranking (with tie) of the top 10 country that has most count.

ID CountryID
1  1
2  1
3  1
4  2
5  3
........  


db.TableA.GroupBy(p => p.CountryID).
        Select(group =>
           new
           {
             Rank = ????????????
             Count = group.Count(),
             Items = group.Select(i => new
             {
                CountryName = i.Country.CountryName
             }).Distinct()
       }).OrderByDescending(group => group.Count)

Rank    CountryName
1       USA
2       UK
2       UK
4       Singapore
5       China
6       France
6       Ukraine
8       Country x
9       Country y
10      Country z
born007
  • 1
  • 1
  • Can you show what results you would expect from the dataset? – stuartd Feb 12 '15 at 10:32
  • i have edit the post with result expected – born007 Feb 12 '15 at 10:47
  • See http://stackoverflow.com/questions/932300/c-sharp-ranking-of-objects-multiple-criteria – stuartd Feb 12 '15 at 10:50
  • hmm the link seems not really fit with this question. the condition i need here is query with grouping while the link is about ranking without need of grouping. I would be glad if someone could provide answer as pure linq to entity to the solution without involving C# class and logic. I have successfully reproduce the top 10 in order and what i lack of here is to display the ranking with ties – born007 Feb 12 '15 at 11:41

0 Answers0