StoyanGrigorov

3.5

Mar 9th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.65 KB | None | 0 0
  1.         private static void StudentStats(StudentSystemDBContext context)
  2.         {
  3.             var students = context.Students
  4.                 .OrderByDescending(x => x.Courses.Sum(z => z.Price))
  5.                 .ThenByDescending(c => c.Courses.Count)
  6.                 .ThenBy(s => s.Name)
  7.                 .ToList();
  8.  
  9.             Console.WriteLine($"Total students: {students.Count}");
  10.             foreach (var student in students)
  11.             {
  12.                 Console.WriteLine($"Name: {student.Name}, Courses: {student.Courses.Count}, Price: {student.Courses.Sum(x => x.Price)}, Average: {student.Courses.Average(a => a.Price)}");
  13.             }
  14.         }
Advertisement
Add Comment
Please, Sign In to add comment