More Effective LINQ

Learn how to fully harness the power of LINQ by exploring best practices and avoiding common pitfalls by solving some fun and challenging problems.
Course info
Rating
(220)
Level
Intermediate
Updated
Mar 1, 2016
Duration
4h 26m
Table of contents
Course Overview
Discovering the Power of LINQ
Thinking in Patterns
Unleashing the Power of Pipelines
Writing Clean and Readable Code
Extending LINQ
Avoiding Unnecessary Work with Laziness
Optimizing Performance
Testing and Debugging Effectively
Embracing a Functional Style
Description
Course info
Rating
(220)
Level
Intermediate
Updated
Mar 1, 2016
Duration
4h 26m
Description

In this course, we will learn how to take full advantage of the power and capabilities of LINQ. We'll see how the LINQ extension methods can be combined together to solve complex problems in a simple and succinct "pipeline." Throughout the course, we'll be attempting to solve some "LINQ Challenges" which you can attempt yourself to reinforce what you are learning. We'll be picking up lots of pro tips that will take your LINQ skills to the next level, including how to extend, debug, optimize, and test LINQ.

About the author
About the author

Mark Heath is a software developer based in Southampton, England, working for NICE Systems as a software architect creating cloud based digital evidence management systems for the police. He is the creator of NAudio, an open source audio framework for .NET.

More from the author
More courses by Mark Heath
Section Introduction Transcripts
Section Introduction Transcripts

Course Overview
Hi, everyone. My name's Mark Heath. And welcome to my course "More Effective LINQ. " I work as a software developer and architect at NICE Systems. LINQ is an extremely powerful and flexible part of the. NET Framework, and has the potential to transform the way you write code as it applies to so many different problem domains. So in this course, we're going to learn about how you can harness the full power of LINQ and get the most out of it. Some of the major topics that we'll cover include constructing LINQ pipelines, extending LINQ, optimizing performance, and making sure we can test and debug our LINQ code effectively. By the end of this course, you'll feel comfortable applying LINQ in all kinds of situations, and know how to extend and optimize it to get the best possible results. Before beginning this course, you should be familiar with the basics of the C# language, and, ideally, have already used a little bit of LINQ. So I hope you'll join me in this journey to learn LINQ with a more effective LINQ course at Pluralsight.

Discovering the Power of LINQ
Hi, my name's Mark Heath, and welcome to this Pluralsight course on More Effective LINQ. This course is designed to equip you with the skills and understanding you need to take full advantage of the power and capabilities of LINQ. And this course will also provide you with plenty opportunities to apply what you're learning by attempting some fun programming challenges as we progress through.

Thinking in Patterns
Hi, Mark Heath here and welcome to the second module in the More Effective LINQ course where we'll be learning all about how you can start thinking in patterns. In the last module, I said that one of the reasons LINQ is so awesome is that it helps you out whenever you're working with less or sequences of data. But for many C# programmers, our first instinct is to create a for or a foreach loop to process the elements in the collection simply because that's what's the most familiar to us and so it's possible to miss many of the places in which LINQ could simplify our code. Now, there's many common patterns that emerge when we're working with collections of objects and it's these patterns that LINQ can help us with. So what we need to do is to train ourselves to spot these repeating patterns that crop up again and again in our day-to-day coding and once we've learned to see these patterns, we can start refactoring our code from what's called an imperative style into a more declarative style thanks to LINQ. And what we mean by those terms is that declarative code expresses what we want to do while imperative code says how it should be done and so by moving the implementation details out of the way, declarative code has the benefit of being a lot more succinct and readable and can express our intent much more clearly. So in this module, I'll be showing you plenty of examples of imperative code and I want you to see if you can guess which of the LINQ extension methods can help us to simplify it before I reveal the answer. So let's get started, but before we go any further, let me introduce our first LINQ challenge, which I want you to try to solve and then I'll be revealing the way I solved it with LINQ at the end of this module.

Unleashing the Power of Pipelines
Hi there. Mark Heath here and welcome to the next module in our more effective LINQ course where we will be learning about unleashing the power of pipelines. Now we ended our last module by solving a fairly straightforward LINQ challenge and saw how we could chain together a series of LINQ extension methods to provide an elegant way to solve a complex problem with a simple set of steps. So in the example we looked at, we chained together Select, OrderBy, Skip and then Sum. And this style of programming is often called a pipeline. So in this module we'll learn more about what pipelines are and what they can do for you. And we'll also be solving some more LINQ challenges together in order to show off what's possible using this programming style as well as seeing some real-world examples of LINQ pipelines. So let's get started and first of all, we're going to look at several types of building blocks or nodes, they are sometimes called that can be used to construct our pipeline.

Writing Clean and Readable Code
Hi. My name's Mark Heath and welcome to this module on writing clean and readable code. Module four of More Effective LINQ. In this module we'll be talking about the importance of writing clean and readable code and the ways in which LINQ can help us to do that. But we'll also see that as you start to embrace the power of LINQ pipelines, as we looked at in the last module, it's possible for things to get pretty complicated. And, so, we'll be learning some simple techniques to ensure that our LINQ code remains as readable as possible. Even when we're applying it to some complicated problems. And once again, I'll be setting some LINQ challenges for you to have a go at. And in this module we'll be focusing, not simply on solving the challenges, but doing so in a way that's as easy to read as possible. So let's get started.

Extending LINQ
Hi, Mark Heath here, and welcome to Module 5 of our more effective LINQ course, where we'll be looking at how and why you should extend LINQ. Now so far in this course, we've seen how the standard library of LINQ extension methods can be combined to solve all kinds of complicated problems using these simple building blocks. But, we also saw at the end of the last module that sometimes, LINQ doesn't offer quite the right method that you want, and so you can find yourself coming up with rather hacky work-arounds, resulting in less elegant and less readable code. So first of all in this module, I want to show how easy it is to create your own extension methods to extend the existing capabilities of LINQ. And we'll start with some very simple examples, and then move on to show how you can take advantage of the pair of generics to make your extension methods broadly applicable to all kinds of problems. And I also want to take the opportunity in this module to point you in the direction of a fantastic open-source library that gives you access to a whole host of useful additions to LINQ. And of course, we'll be attempting a few more LINQ challenges as we progress. So let's get started.

Avoiding Unnecessary Work with Laziness
Hi, Mark Heath here, and welcome to Module Six in our More Effective LINQ course. In this Module, we'll be learning how to avoid unnecessary work with laziness. Now of course, most people don't really think of laziness as a virtue. Probably when you're at school, your teachers didn't encourage you to be as lazy as possible. However, when we're talking about laziness in programming, what we mean is avoiding doing any more work than you need to. And, that's a good thing. It makes our programs more responsive and uses less battery power when it's running on mobile devices. And so in this Module, I'm going to give you three ways to be lazy, and we'll see how they each apply to our LINQ code. The first way to be lazy is avoid starting any work until you know you need to do it. And so, we'll be learning about the concepts of deferred execution. How LINQ helps you avoid iterating through your enumeration until you really need to. The second way to be lazy is don't do any more work than you absolutely need to. And so, we'll look at breaking out of iterating through sequences early, as soon as we've got the data we need. We want to evaluate as few elements in the sequence as possible to get our desired result. And the third way to be lazy is don't do anything more than once. And so, we'll look at why it's not a good idea to iterate through the same sequence multiple times. So, let's get started.

Testing and Debugging Effectively
Hi, Mark Heath here, and in this module we're going to answer the question, how can I effectively debug and test my LINQ queries? Now, in this course, we've seen lots of examples of LINQ pipelines that can solve quite complicated problems in relatively few lines of code. But what happens when things go wrong? What if what comes out of your pipeline isn't what you were expecting? Or maybe nothing is coming out at all. How can you go about debugging a LINQ pipeline, especially since it's just one long line of code? And so many of the debugging techniques that you might normally use aren't so easy to apply. So in this module, we'll look at some techniques you can use to help you debug more effectively. And we'll also talk about unit testing LINQ our pipelines. These days, most developers understand the importance and benefits of unit tests, but there are times maybe when we leave a bit of code untested because it seems too difficult to work out how to get it under test. And sometimes LINQ queries can be like that. So we'll look at some ways to make unit testing your LINQ queries a bit less painful. And finally we're going to look at how you can handle exceptions. How should we respond when something goes wrong in our LINQ pipeline? Is there a way that we can wrap individual stages in the pipeline in exception handlers? And is there a way we can carry on iterating through a sequence even though some of the elements have caused exceptions to be thrown? And we'll be seeing a few different ways that you can respond to exceptions. So we're going to start off by looking at debugging.