Module 3: Introduction to LINQ (PowerPoint Slides)

16
Visual Studio 2008 Training 3.5 3.5 RTM RTM Mohamed Saleh [email protected] www.jordev.net www.geeksconnected.com/mohamed

description

Module 3: Introduction to LINQ (PowerPoint Slides)Jordan .NET User Group (Jordev)Community MaterialMohamed Saleh

Transcript of Module 3: Introduction to LINQ (PowerPoint Slides)

Page 1: Module 3: Introduction to LINQ (PowerPoint Slides)

Visual Studio 2008 Training

3.5 RTM3.5 RTM

Mohamed [email protected]

www.jordev.netwww.geeksconnected.com/mohamed

Page 2: Module 3: Introduction to LINQ (PowerPoint Slides)

Module 3: Introduction To Linq

Page 3: Module 3: Introduction to LINQ (PowerPoint Slides)

Overview

What is Linq

Understand the Query Expressions and Query Operators

Writing queries using extension methods

Using the Partitioning and Conversion operators

Explain the usage of the new Linq Assemblies

Enabling Linq to Objects for .Net Framework 2.0

Page 4: Module 3: Introduction to LINQ (PowerPoint Slides)

Introducing LINQ Project

Linq is a set of language extensions that enable the query operations over the data.

Linq relies on the C# 3.0 Language Enhancements .

Linq Building Blocks:1. Object Initializers

2. Lambda Expressions

3. Extension Methods

4. Anonymous types

5. Implicit Typing Variables

LINQ Project Overview

Page 5: Module 3: Introduction to LINQ (PowerPoint Slides)

LINQ Assemblies

The following describes the new assemblies and its use:• System.Core.dll: Extension Methods for IEnumerable<T> .

• System.Data.DataExtensions.dll: Providing LINQ for DataSet.

• System.Data.Linq.dll: LINQ implementation for SQL Server.

• System.Xml.Linq.dll: LINQ Implementation for XML

LINQ Assemblies

Page 6: Module 3: Introduction to LINQ (PowerPoint Slides)

LINQ Query Expressions

What is Query?

What is Query Operators?

How to Write Query Expressions?

IEnumerable<T> and Query Results

What is Deferred Execution?

What is Immediate Execution?

LINQ Query Expressions

Page 7: Module 3: Introduction to LINQ (PowerPoint Slides)

Lab 1: Writing Query Expressions

Writing Linq Query Expression.

Using Query Operators.

Using var and IEnumerable<T> query varaiables.

Querying In-Memory Collections.

Page 8: Module 3: Introduction to LINQ (PowerPoint Slides)

Standard Query Operators

The System.Linq namespace contains different Linq Extensions under the System.Linq.Enumerable class.

Commonly Used Operators:1. OrderByDescending

2. OrderBy

3. Take

4. Sum

5. Distinct

6. Count

7. First

Standard Query Operators Overview

Page 9: Module 3: Introduction to LINQ (PowerPoint Slides)

Lab 2: Using Initializers

Writing Queries using Linq Extension Methods.

Sorting the elements using the OrderByDescending extension method.

Returning specific elements using Take and First methods.

Calculating the total number of elements using the Count method.

Returning Distinct values from a sequence of values.

Page 10: Module 3: Introduction to LINQ (PowerPoint Slides)

Conversion Operators

The conversion operator enable the conversion of query results into different collection types.

The query conversion operators:

1. ToArray

2. ToList

3. ToDictionary

4. OfType

Conversion Operators Overview

Page 11: Module 3: Introduction to LINQ (PowerPoint Slides)

Lab 3: Using Conversion Operators

Enforce the immediate execution of the queries.

Converting the query results to Different Collection Types.

Filtering the query results based on a specific data type.

Page 12: Module 3: Introduction to LINQ (PowerPoint Slides)

Partitioning Operators

Linq extension methods set contain a group of operators that allows the programmer to partitioning the results of the query into a specific sequence.

The query partitioning operators:1. Take

2. Skip

3. TakeWhile

4. SkipWhile

Partitioning Operators Overview

Page 13: Module 3: Introduction to LINQ (PowerPoint Slides)

Lab 4: Using Partitioning Operators

Use the partitioning query operators.

Skipping elements based on conditional expression.

Retrieving elements using Take and TakeWhile operators.

Page 14: Module 3: Introduction to LINQ (PowerPoint Slides)

LINQ Bridge

LINQ Implemented for .NET 3.5, which requires the client to install .NET Framework 3.5.

LINQBridge is an open project contains a reimplementation for all standard query operators

LINQBridge utilize the Csharp 3.0 Compiler new features to enable LINQ for .NET 2.0 Applications.

LINQBridge can be used in Visual Studio 2008 for writing LINQ to Objects expressions.

LINQBridge can be used in Visual Studio 2005 using the extension methods style.

LINQ Bridge Overview

Page 15: Module 3: Introduction to LINQ (PowerPoint Slides)

Lab 5: Using LINQ for .NET Framework 2.0

Writing Linq-Enabled Applications for .NET Framework 2.0.

Using the LinqBridge Extension in Visual Studio 2008.

Writing Linq to Objects expressions.

Page 16: Module 3: Introduction to LINQ (PowerPoint Slides)

Review

In this module, you learned to:In this module, you learned to:

Writing Query Expressions

Writing Queries using extension methods directly

Using different query operators

Enabling Linq to Objects into .NET Framework 2.0 Applications

Writing Query Expressions

Writing Queries using extension methods directly

Using different query operators

Enabling Linq to Objects into .NET Framework 2.0 Applications