Exercise: LINQ to Objects

In this exercise you must use LINQ to Object.

Very much like the example linqFirstTry.

Getting started

Create a new Solution in Visual Studio. Name the Solution LinqSchool (or something similar).

Model class Teacher

Create a simple class Teacher with properties Id, Name, and Salary.

Override the ToString(...) method in the Teacher class.

Main class

In the Main class (the class where you have your Main method) create a List of Teachers, with at least 4 Teacher objects.

All teachers

  1. Make a LINQ statements (query syntax) to return all teachers from the List of Teachers.
    Print the result to the screen.
  2. Make a LINQ statement (expression syntax) to return all teacher ...
    Print the result to the screen.

Teachers with a high salary

  1. Make a LINQ statements (query syntax) to return all teachers with a salary higher than some amount.
    Print the result to the screen.
  2. Make a LINQ statement (expression syntax) to return all teacher ...
    Print the result to the screen.

Teachers with a high salary, changing the enviromnent

  1. Make a LINQ statements (query syntax) to return all teachers with a salary higher than someAmount.
    Change the value of someAmount.
    Print the result to the screen.
  2. Make a LINQ statement (expression syntax) to return all teacher ...
    Change the value of someAmount.
    Print the result to the screen.

Ordering the result

  1. Make a LINQ statements (query syntax) to return all teachers ordered by name.
    Print the result to the screen.
  2. Make a LINQ statement (expression syntax) to return all teacher ...
    Print the result to the screen.

Joining Teacher and Course

In this part of the exercise you must join Teachers and Courses

Model class Course

Create a simple class Course with properties Name, Credits and TeacherId.

In the Main class create a List of Courses with at least 3 Courses.
Make sure the Courses TeacherId match an existing Teacher object.

Joining ...

  1. Make a LINQ statements (query syntax) to return {courseName, teacherName} for all courses.
    Print the result to the screen.
  2. Extra: Make a LINQ statement (expression syntax) to return ...
    Print the result to the screen.

Extra: Group by

Try LINQ group by.

Try to group Courses by TeacherId.