18
Introduction to LINQ Pakorn Weecharungsan

D4 Introduction to LINQ

Embed Size (px)

DESCRIPTION

Introduction to LINQ with C# programming

Citation preview

Page 1: D4 Introduction to LINQ

Introduction to LINQ

Pakorn Weecharungsan

Page 2: D4 Introduction to LINQ

Contents

What is LINQ? LINQ Providers Fundamental LINQ syntax

Page 3: D4 Introduction to LINQ

What is LINQ?

LINQ (Language Integrated Query) is a new feature of C# and Visual Basic .NET that integrates into these languages the ability to query data

Page 4: D4 Introduction to LINQ

What is LINQ?

Page 5: D4 Introduction to LINQ

LINQ Providers

LINQ to Objects LINQ to XML LINQ Support for ADO.NET

LINQ to SQLLINQ to DatasetsLINE to Entities

Page 6: D4 Introduction to LINQ

Query Syntax and Method Syntax

Query syntax is a declarative form that looks very much like an SQL statement. Query syntax is written in the form of query expressions

Method syntax is an imperative form, which uses standard method invocations. The methods are from a set called the standard query operators

Page 7: D4 Introduction to LINQ

Query Syntax and Method Syntax

Page 8: D4 Introduction to LINQ

The Structure of Query Expressions

Page 9: D4 Introduction to LINQ

The from clause

The from clause specifies the data collection that is to be used as the data source. It also introduces the iteration variable

Page 10: D4 Introduction to LINQ

The join clause

The join clause in LINQ is much like the JOIN clause in SQL

Page 11: D4 Introduction to LINQ

The where Clause

The where clause eliminates items from further consideration if they don’t meet the specified condition. The syntax of the where clause is the following

Page 12: D4 Introduction to LINQ

The where Clause

Page 13: D4 Introduction to LINQ

The orderby Clause

The orderby clause takes an expression and returns the result items in order according to the expression

Page 14: D4 Introduction to LINQ

The orderby Clause

Page 15: D4 Introduction to LINQ

The group Clause

The group clause groups the selected objects according to some criterion. For example, with the array of students in the previous examples, the program could group the students according to their majors

Page 16: D4 Introduction to LINQ

The group Clause

Page 17: D4 Introduction to LINQ

The Standard Query Operators

The standard query operators comprise a set of methods called an application programming interface (API) that lets you query any .NET array or collection

Page 18: D4 Introduction to LINQ

The Standard Query Operators