Querying Entities and Associations
In this task, you will create strongly-typed queries against the CLR objects that represent entities and associations in the School model, and bind display controls to the object collections returned from these queries.
At the beginning of the code file for the CourseViewer form, add the following using (C#) or Imports (Visual Basic) statements to reference the model created from the School database and the entity namespace.
At the top of the partial class definition for the CourseViewer form, add the following code that creates an ObjectContext instance.
In the CourseViewer form designer, double-click the CourseViewer form.
This opens the code page for the form and creates the courseViewer _Load event handler method.
In the courseViewer _Load event handler method, copy and paste the following code that defines the DataGridView, executes a query that returns a collection of departments (ordered by Name), and binds the collection of Department objects to the departmentList control.
You have successfully created queries that return Department and Course objects and bound those objects to controls. Next, you will save changes made to Course objects in the data grid back to the database: Inserting and Updating Data.