This is a console app-based project template to help you demonstrate how the standard query operators of the Language Integrated Query, LInQ work during your classes, courses or demos.
When creating the project template I had three goals in mind:
In order to realize these goals, basic console-app template is extended with a simple data model, a data repository and some extension methods. After you install the extension, you'll find a new project template in Visual Studio:
The data model
The data model is based on the late-and-great Northwind database, or at least parts of it. You can find the elements of the data model inside the Model folder of the project.
The Product class
The Product class represents a product that you can buy at a store.
The Category class
The Category class represents a product category; basically a product group (e.g. "Books", "Drinks").
Note that everything is wired together by reference and there is exactly one of each object in the data source, no matter whether you access it directly from the data source, from the Category property of a Product or from the Products property of a Category. This is an important piece of information when discussing operators that do equality comparison, like the set operators, joins or GroupBy().
Note that both classes have their ToString() method overridden to return the value of their Name property.
Note that the namespace of the model classes, Model is already referenced in Program.cs. If you add other files, you have to add the reference to the namespace yourself.
The data repository
Instances of the model classes are available through the static DataRepository class in the DataSource folder. The class has two static properties:
The properties are instantiated and populated in the static constructor of the class. The data for the properties come from the two XML files in the DataSource folder, which were exported from the Northwind database using the DataContractSerializer.
Please make sure to make your students aware that the static class and static properties are only used here for the sake of simplicity and this is by no means a best practice to implement data sources.
Note that the properties are actually of type List at runtime.
Note that the namespace of the DataRepository class, DataSource is already referenced in Program.cs. If you add other files, you have to add the reference to the namespace yourself.
The Dump() extension method
In order to visualize the results of queries, an extension method called Dump() was implemented to the IEnumerable type. The Dump() method has the following capabilities:
Note that the namespace of the class of the extension method, Extensions is already referenced in Program.cs. If you add other files, you have to add the reference to the namespace yourself.
Please make sure to discuss with your students how LInQ query evaluation works and the inner implementation of Dump() triggers query evaluation.
##Licensing and terms, contribution and other materials
You are welcome to use this extension during your presentations, classes or courses with the limitations of the MIT license (which is not that much :) ). But use it at your own risk :) and always test your demos beforehand (especially in the case of Dump() which was not tested extensively).
If you have ideas, requests or comments, visit the Github page of the extension.
For other teaching aids and materials, check out my blog.