.NET Essentials: Working with LINQ

.NET Essentials: Working with LINQ

3h 5mIntermediate2020-09-16

Authors

Walt Ritscher

Walt Ritscher

Programmer, UI Designer, Staff Instructor at LinkedIn Learning

Course details

Want a simpler, more consistent way to query data ? Language-Integrated Query (LINQ) may be what you're looking for. This general-purpose query toolset allows allows developers to filter, sort, aggregate, and query data directly within C# code. In this course, join Walt Ritscher as he helps you get up and running with LINQ, focusing on LINQ to Objects. Walt begins by showing how to use LINQPad, the code editor and code runner you can use to write and test the LINQ examples provided in this course. He then highlights the key .NET features that power LINQ, the essential elements of a query, and the different types of query expressions. Plus, learn about filters, aggregates, groups, element operations, quantifying data, and partition tools. Along the way, Walt provides challenges that help you grasp how to apply these concepts in the real world.

Skills covered

.NETDatabase DevelopmentDatabase ManagementSoftware Development ToolsMicrosoftSoftware DevelopmentOne-Off

Concepts

Introduction

  • Welcome
  • What you should know
  • How to access the sample code on GitHub

The Spirit of LINQ

  • Why build a query engine in a programming language
  • Explore LINQ essential parts

Work with LINQPad

  • Why use LINQPad
  • Initial tour of LINQPad
  • Set destination folder for course examples
  • Explore the expression editor
  • Explore the statements editor
  • Show formatted output with the Dump method
  • Explore the program editor
  • Run a subset of code

Key Parts of .NET

  • Implicit variable typing
  • Anonymous types
  • Object initializers
  • Collection initializers
  • Inline code with lambda expressions
  • Extension methods
  • More extension methods
  • Generic types

The Parts of a Query

  • What sources are queryable
  • The Enumerable class
  • Learn how to use the Enumerable static methods
  • Learn how to use the Enumerable extension methods
  • Learn how to use the Query Expression syntax
  • What sources revisited
  • Deferred execution - When does the query run
  • Combine methods with execution pipelines
  • Combine extension methods and query expressions

Generate

  • The Empty and DefaultIfEmpty methods
  • The Repeat method
  • The Range method

Basics

  • The three types of query expressions
  • Review query expression clauses
  • Examples of three query expressions
  • The select clause
  • Learn how to use select to project into another type
  • Select into anonymous type
  • Learn how to use expressions with select
  • Challenge - Write select expressions
  • Solution - Write select expressions
  • Index into another sequence

Filtering

  • The Where method
  • Learn how to use logical operators with the Where method
  • Explore the OfType class definitions
  • The OfType method
  • Challenge - Filter results with Where
  • Solution - Filter results with Where

Aggregation

  • Sum, Average, and other aggregates
  • Create custom aggregates

Groups and Other Stuff

  • The GroupBy method
  • GroupBy query expression
  • GroupBy with ElementSelector
  • GroupBy with ResultSelector
  • Iterate over groups
  • Combine two sequences
  • Flatten sequence with SelectMany
  • Challenge - Group results by color values
  • Solution - Group results by color values

Element Operations

  • First and Last methods
  • The FirstOrDefault method
  • The ElementAt method
  • Single and SingleOrDefault methods

Set Operations

  • The Distinct method
  • The Intersect method
  • The Union method
  • The Except method
  • Find duplicate values

Quantify Data

  • Learn how to use the Any method to detect empty sequence
  • Learn how to use Any method to determine if element exists
  • The Contains method
  • The All method

Partition

  • Skip and Take methods
  • Conditional Skip and Take methods

Other

  • Learn how to use LINQ in a .NET application
  • Learn how to use MoreLinq for extended query syntax
  • Additional MoreLinq examples

Continue Your Journey

  • Next steps
80,000 Toman