Exercise: Group directors by their birth year using LINQ query expressions

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

The answer to the exercise will be included and explained if you attend the Wise Owl course listed below!

Category ==> Visual C Sharp 2010  (65 exercises)
Topic ==> Grouping using LINQ  (2 exercises)
Level ==> Average difficulty
Course ==> Adv C# | Classes & LINQ
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help).

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

If you haven't already done so:

  1. Go into SQL Server Management Studio.
  2. Open the file with the SQL extension in the above folder.
  3. Run this to create the Movies database.

Now use the Object/Relational designer to create a new LINQ to SQL classes item data context model:

Movies data model

No need to rename any entities or properties ...


Create a form called frmFilmDirectorsByBirthYear, and within this create code to display directors grouped by their year of birth, excluding anyone born before 1950:

The directors by year of birth

The start of the output from your code.


You'll need to convert the DirectorDOB property in the model to DateTime format before you can access its Year property.

Close down any open windows!

This page has 0 threads Add post