Practical LINQ


Deborah Kurata, Microsoft MVP

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.

This course forms part of the following learning paths:

Practical LINQ by Deborah Kurata

This course is composed of six modules but the first is just a 5 overview of the course and the last is a 2 min summary of the course.

There are several Pluralsight courses on LINQ, and I previously watched Scott Allen’s three courses which teach LINQ in some depth.

This course is a faster route to getting up and running quickly with LINQ and can reasonably be watched and understood in under 3 hours.

Even if you don’t have a Pluralsight subscription, you can find many useful LINQ examples on Deborah’s blog

LINQ By Example

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

Comparing/combining – the Set operators Intersect, Except, Union, Distinct, Concat

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.

Related Courses:

Deborah has recently produced C# Best Practices: Collections and Generics, which features a module on LINQ.

Mark Heath has recently produced More Effective LINQ, which might be a good follow on option from Practical LINQ.

Scott Allen has produced thre part series on LINQ, the first course in this series is LINQ Fundamentals

4 thoughts on “Practical LINQ

  1. Pingback: C# End to End Learning Path | Zombie Code Kill

  2. Pingback: C# Tips and Traps 2 | Zombie Code Kill

  3. Pingback: Clean Code: Writing Code for Humans | Zombie Code Kill

  4. Pingback: One ASP.NET From Scratch | Zombie Code Kill

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s