Practical LINQ

Welcome to this review of the Pluralsight course Practical LINQ by Deborah Kurata.

Deborah is an independent software consultant specializing in the development of successful Web (Angular JS) and Windows (.NET) applications. She has authored several books and created 14 courses on Pluralsight.

Covers the main terminology: Lambdas, Extension methods, LINQ syntax vs Method syntax etc. Covers basic examples such as refactoring a for each loop into a more terse and expressive LINQ statement that finds a particular value of interest.

More LINQ Examples

Examples include:

Sorting – OrderBy/ThenBy/OrderByDescending and Reverse

Creating – Enumerable.Range (as featured in C# Tips and Traps but paired with .Select) and Enumerable.Repeat

Transforming with projections – this is a long 23 minute clip which includes Anonymous types, some of the pros and cons of the dynamic keyword, and examples of working with relational databases.

Working with parent/child data using the SelectMany operator. Deborah explains the shortcomings of the Select operator and why SelectMany is sometimes preferred.

Data Binding

Data binding is a technique for connecting a data source to a user interface control. This module covers data binding in two Microsoft desktop technologies: Windows Forms, and Windows Presentation layer. Each clip is nearly half an hour long so you will probably only want to watch the clip covering the technology that you use in your own applications.

The Windows Forms DataGrid works with a retrieve method in a repository class “like magic” and is editable, but has no sorting functionality or other useful user friendly features. The earlier examples created our sort methods, and these are easily made to work with a DataGrid if we remember to execute our LINQ query by using .ToList()

This video clip covers one of the potential problems with using the dynamic keyword that was introduced in the previous module, and how to make it work correctly.

Deborah warns that using Anonymous types is going to lead to a DataGrid control that is not editable.

Also covered is binding to a ComboBox. This example also uses the dynamic keyword. Then we see how to display a DataGrid based on our selection in our ComboBox. This makes uses of the Find example from the first module.

I found this to be a nice, simple application. If the business needs are simple enough, you could use these techniques to write a real world application in less than an hour.

Doing this in Windows Presentation Foundation (WPF) requires a bit more setup work, due to the Model-View-ViewModel architecture that it uses. Using the dynamic keyword no longer works when we want updatable data and we need to create a new class for our model.

However WPF gives you greater control than Windows Forms (in a similar way to how ASP.NET MVC gives you greater control than Web Forms) and the resulting application looks more aesthetically pleasing than our Windows Forms application.

So if you are not already using Windows Forms, and you want to get started as a Windows desktop application developer, it may be worth the effort needed to learn more modern technology than Windows Forms. If you are new to WPF, there are several other Pluralsight courses available that teach it from scratch. An even more modern technology is Windows 10 universal apps, which like WPF is based on XAML (XML Application Markup Language)

Analyzing Data

This covers Totalling, Grouping and Averaging data.

Totalling is done by using the .Sum extension method.

The GroupBy method allows us to either group by a single property, by multiple properties, or by a parent property. This module shows all of these techniques. We all see how to show the results in a WPF pie chart.

The video clip on averaging data shows us that the .Average method returns a mean average. We also see algorithms for calculating the median and mode of a list of values.