I have an collection of students and collection of universities. For each university i need to pick student with highest score. I want to group universities by name and select student that got highest score in that univesity. Like this:
Country | Name | Student | Score
New York| NY University | Bob | 120
LA | LA Univesity | Tom | 140
So far i got there
return from university in Universities
join country in Countries on university.Id equals country.Id
orderby country.Name
group university by university.Name into g
select new
{
g.Key,
maxScore = g.Max(student => student.Score) <-- student.Score is only available in Students class
};
Problem is university only got access to students id i.e each Universty got only thos fields:
int Country.Id,
string Name,
int Student.Id
and problem is how do i get only 1 student with max score in that g group.
Student:
Id,
Name,
Score