Help with this Linq query
I'd like to get a collection of Students whose average grade (by adding each individual subject score and dividing by the amount of subjects) is above 55.
Since this year is 2011, I also need to calculate this field only for the 2011 records.
private void cmbGr开发者_如何学编程adeParalelo_SelectedIndexChanged(object sender, EventArgs e)
{
StudentRepository studentRepo = new StudentRepository():
dataGridView1.DataSource = studentRepo.FindAllStudents()
.Where(s=>s.ScoreRecords.)
}
Any suggestions?
Assuming every student may have multiple ScoreRecords, maybe try
dataGridView1.DataSource = studentRepo.FindAllStudents
.Where(s=> s.ScoreRecords
.Where(r => r.Year == 2011)
.Average(r => r.FinalGrade) > 55)
.Where(s=>s.ScoreRecords.Year == 2011).Average(f => f.FinalGrade) > 55));
精彩评论