SlideShare a Scribd company logo
 The full form of LINQ is 'Language Integrated Query,' and introduced in .NET Framework
3.5 to query the data from different sources of data such as collections, generics, XML
documents, ADO.NET Datasets, SQL, Web Services, etc.
 In C# and VB.NET. LINQ provides the rich, standardized query syntax in a .NET programming
language such as C# and VB.NET, which allows the developers to interact with any data sources.
 In C# or VB.NET, LINQ functionality can be achieved by importing the System.Linq namespace
in our application. Generally, the LINQ contains a set of extension methods which allows us to
query the source of data object directly in our code based on the requirement.
 LINQ
LINQ Architecture
The responsibility of the LINQ provider is to convert the LINQ
Query into a format so that the data source can understand it.
Advantages of LINQ
 We don’t required to learn new query language syntaxex from different sources of data
because LINQ provide standard query syntax.
 We have to write less code in comparison to traditional approach.
 LINQ provides the compile-time error checking as well as intelligence support in Visual
Studio. This powerful feature helps us to avoid run-time errors.
 LINQ provides a lot of built-in methods that we can be used to perform the different
operations such as filtering, ordering, grouping, etc. which makes our work easy.
 The query of LINQ can be reused.
 With the use of LINQ, it's very difficult to write a complex query like SQL.
 It was written in the code, and we cannot make use of the Cache Execution plan, which is the SQL
feature as we do in the stored procedure.
 If the query is not written correctly, then the performance will be degraded.
 If we make some changes to our queries, then we need to recompile the application and need to
redeploy the dll to the server.
Disadvantages of LINQ
Linq Syntax
 The requirement for writing the LINQ Query
To write the LINQ Query, we need the following three things:
 Data Source (in-memory objects, SQL, XML)
 Query
 Execution of the Query
 What is a Query?
A query is nothing but a set of instructions. Queries are applied to the data source (i.e., in-memory object,
SQL, XML, etc.) to perform the operations (i.e., CRUD operations) and show the shape of the output from
that Query. This means that the Query is not responsible for what will be the output; instead, it is responsible
for the shape of the output.
Each Query is a combination of three things; they are:
 Initialization(to work with a particular data source)
 Condition(where, filter, sorting condition)
 Selection (single selection, group selection or joining)
LINQ Lambda Expression
The syntax of defining the lambda expression in LINQ is as:
(Input Parameter) => Method Expression
The name of the parameter can be anything and ahead of this parameter (=>) is an Equal to (=) followed by
a greater than (>) symbol which is used to send or pass the parameter from left to right side, and on the
right-hand side we perform the operation using the input parameter which we will pass from the left-hand side
parameter.
Example: X=>x+10
Here, x is an input parameter which is followed by => operator, and next to the operator, there is an expression
that ads numeric 10 to the input variable (x). Now the output would increment the numeric 10 to x variable,
which was the input parameter on the left-hand side of the Expression.
 Aggregate Functions
 LINQ Min() Function and Max() Function
MIN () function of LINQ is useful to get the minimum value from a collection or list whereas Max
() function of LINQ is useful to get the maximum value
int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int m = a.Min(); or int m = a.Max();
From the above syntax, we are getting the minimum and maximum value from the "a" list using the
LINQ Min () or Max() function.
 LINQ Sum() Function
In LINQ sum() function is used to calculate the sum of the items in collections/lists.
int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int sum = a.Sum();
From the above syntax, we are summing up the items in the “a" list using the LINQ Sum function.
 LINQ Count() function
COUNT () function in LINQ is used to count the number of elements in the list or collection.
int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int m = a.count();
 LINQ Aggregate() Function
int[] Num = { 1, 2, 3, 4 };
double Average = Num.Aggregate((a, b) => a + b);
Output 10 ((1+2)+3)+4 )
in the above syntax, we take two elements 1 and 2 to perform the addition and make 3 then it take
the previous result 3 and next element 3 and perform the addition to make the 6 to the next
4 and result will be 10.
Ex. Now we will calculate the average of the numbers by applying the Aggregate function.
double Average = Num.Aggregate((a, b) => a * b);
Output 362880 ((((((((1*2)*3)*4)*5)*6)*7)*8)*9)
LINQ Sorting Operator
 Sorting Operators in LINQ are used to change the order or sequence of the data (either
ascending or descending), which is based on one or more attributes.
 LINQ OrderBy Operator(Ascending)
In LINQ, the OrderBy operator is used to sort the list/ collection values in ascending order. In
if we use order by the operator by default, it will sort the list of values in ascending order. We
need to add any ascending condition in the query statement.
Ex. var s = Obj.OrderBy(x => x.Name);
foreach (var student in s) Console.WriteLine(student.Name);
 LINQ OrderBy Descending Operator
In LINQ, the OrderBy operator is used to sort the list/ collection values in descending order.
Ex. var s = Obj.OrderByDescending (x => x.Name);
foreach (var student in s) Console.WriteLine(student.Name);
 LINQ ThenBy Operator
If we want more than one condition on sorting in LINQ, then we use the ThenBy clause with the
OrderBy clause. In LINQ, OrderBy is the primary sorting operator, and ThenBy is the secondary
operator.
In the above example, we are sorting the
"ObjStudent" list item using the multiple
fields Name, RoleNumber Id.
 LINQ ThenByDescending Operator
In LINQ, ThenByDescending operator is used to implement the sorting on multiple fields in the
list/ collection, and by default, ThenByDescending operator will sort the list of items in descending
order. In LINQ, we use the ThenByDescending operator along with OrderBy operator.
 Partition Operators
In LINQ, Partition Operators are used to partition the list/collections items into two parts and return one part of
the list items. Here are the different types of partitioning operators available in LINQ.
Take() and TakeWhile()
In LINQ, Take Operator is used to get the specified number of elements in sequence from the
list/collection. The LINQ takes the Operator will return the specified number of elements from the
starting of collection or list.
Ex. string[] countries = { "India", "USA", "Russia", "China", "Australia", "Argentina" };
IEnumerable<string> result = countries.Take(3);
foreach (string s in result) Console.WriteLine(s);
LINQ, TakeWhile Operator is used to get the elements from the list/collection of the data source as
long as the specified condition is holding the expression or until the condition is false.
Ex. string[] countries = { "India", "USA", "Russia", "China", "Australia", "Argentina" };
IEnumerable<string> result = (from x in countries select x).TakeWhile(x => x.StartsWith("U"));
foreach (string s in result) Console.WriteLine(s);
LINQ SKIP OPERATOR
In LINQ, the Skip operator is used to skip the specified number of elements from the list/collection
and return the remaining elements
Ex. string[] countries = { "India", "USA", "Russia", "China", "Australia", "Argentina" };
IEnumerable<string> result = countries.Skip(3);
foreach (string s in result) Console.WriteLine(s);

More Related Content

PPT
PPTX
Think in linq
PPT
Linq in C# 3.0: An Overview
PPTX
LINQ PPT.pptx
PPT
Language Integrated Query - LINQ
PPTX
Asp.net c# mvc Training-Day-5 of Day-9
DOCX
Linq in C#
PPTX
LINQ in C#
Think in linq
Linq in C# 3.0: An Overview
LINQ PPT.pptx
Language Integrated Query - LINQ
Asp.net c# mvc Training-Day-5 of Day-9
Linq in C#
LINQ in C#

Similar to LINQ.pptx (20)

PPTX
Link quries
PPTX
Introduction to LINQ in UiPath with examples.pptx
PDF
Module 3: Introduction to LINQ (Material)
PDF
New c sharp3_features_(linq)_part_v
PPT
Module 3: Introduction to LINQ (PowerPoint Slides)
PDF
Litwin linq
PPT
Linq
PDF
Beginning linq
PPTX
SQL ttrain wrwrwrw wwrw wwrrrwrwrwrwwrwr.pptx
PPT
PPT
Of Lambdas and LINQ
DOCX
Project_Report (BARC-Jerin)_final
PPT
C#3.0 & Vb 9.0 New Features
ODP
New c sharp3_features_(linq)_part_iv
PDF
Intake 38 data access 3
PDF
Linq Pocket Reference Pocket Reference Oreilly 1st Edition Joseph Albahari
PPT
Understanding linq
PPTX
C# advanced topics and future - C#5
PPTX
Understanding LINQ in C#
Link quries
Introduction to LINQ in UiPath with examples.pptx
Module 3: Introduction to LINQ (Material)
New c sharp3_features_(linq)_part_v
Module 3: Introduction to LINQ (PowerPoint Slides)
Litwin linq
Linq
Beginning linq
SQL ttrain wrwrwrw wwrw wwrrrwrwrwrwwrwr.pptx
Of Lambdas and LINQ
Project_Report (BARC-Jerin)_final
C#3.0 & Vb 9.0 New Features
New c sharp3_features_(linq)_part_iv
Intake 38 data access 3
Linq Pocket Reference Pocket Reference Oreilly 1st Edition Joseph Albahari
Understanding linq
C# advanced topics and future - C#5
Understanding LINQ in C#
Ad

Recently uploaded (20)

PDF
creating-agentic-ai-solutions-leveraging-aws.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
PPTX
How Much Does It Cost to Build a Train Ticket App like Trenitalia in Italy.pptx
PDF
Why Endpoint Security Is Critical in a Remote Work Era?
PDF
Google’s NotebookLM Unveils Video Overviews
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
PDF
Software Development Methodologies in 2025
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PPTX
CroxyProxy Instagram Access id login.pptx
PPTX
ABU RAUP TUGAS TIK kelas 8 hjhgjhgg.pptx
creating-agentic-ai-solutions-leveraging-aws.pdf
Understanding_Digital_Forensics_Presentation.pptx
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
How Much Does It Cost to Build a Train Ticket App like Trenitalia in Italy.pptx
Why Endpoint Security Is Critical in a Remote Work Era?
Google’s NotebookLM Unveils Video Overviews
GamePlan Trading System Review: Professional Trader's Honest Take
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
Software Development Methodologies in 2025
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
NewMind AI Monthly Chronicles - July 2025
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
CroxyProxy Instagram Access id login.pptx
ABU RAUP TUGAS TIK kelas 8 hjhgjhgg.pptx
Ad

LINQ.pptx

  • 1.  The full form of LINQ is 'Language Integrated Query,' and introduced in .NET Framework 3.5 to query the data from different sources of data such as collections, generics, XML documents, ADO.NET Datasets, SQL, Web Services, etc.  In C# and VB.NET. LINQ provides the rich, standardized query syntax in a .NET programming language such as C# and VB.NET, which allows the developers to interact with any data sources.  In C# or VB.NET, LINQ functionality can be achieved by importing the System.Linq namespace in our application. Generally, the LINQ contains a set of extension methods which allows us to query the source of data object directly in our code based on the requirement.  LINQ
  • 2. LINQ Architecture The responsibility of the LINQ provider is to convert the LINQ Query into a format so that the data source can understand it.
  • 3. Advantages of LINQ  We don’t required to learn new query language syntaxex from different sources of data because LINQ provide standard query syntax.  We have to write less code in comparison to traditional approach.  LINQ provides the compile-time error checking as well as intelligence support in Visual Studio. This powerful feature helps us to avoid run-time errors.  LINQ provides a lot of built-in methods that we can be used to perform the different operations such as filtering, ordering, grouping, etc. which makes our work easy.  The query of LINQ can be reused.
  • 4.  With the use of LINQ, it's very difficult to write a complex query like SQL.  It was written in the code, and we cannot make use of the Cache Execution plan, which is the SQL feature as we do in the stored procedure.  If the query is not written correctly, then the performance will be degraded.  If we make some changes to our queries, then we need to recompile the application and need to redeploy the dll to the server. Disadvantages of LINQ
  • 5. Linq Syntax  The requirement for writing the LINQ Query To write the LINQ Query, we need the following three things:  Data Source (in-memory objects, SQL, XML)  Query  Execution of the Query  What is a Query? A query is nothing but a set of instructions. Queries are applied to the data source (i.e., in-memory object, SQL, XML, etc.) to perform the operations (i.e., CRUD operations) and show the shape of the output from that Query. This means that the Query is not responsible for what will be the output; instead, it is responsible for the shape of the output.
  • 6. Each Query is a combination of three things; they are:  Initialization(to work with a particular data source)  Condition(where, filter, sorting condition)  Selection (single selection, group selection or joining)
  • 7. LINQ Lambda Expression The syntax of defining the lambda expression in LINQ is as: (Input Parameter) => Method Expression The name of the parameter can be anything and ahead of this parameter (=>) is an Equal to (=) followed by a greater than (>) symbol which is used to send or pass the parameter from left to right side, and on the right-hand side we perform the operation using the input parameter which we will pass from the left-hand side parameter. Example: X=>x+10 Here, x is an input parameter which is followed by => operator, and next to the operator, there is an expression that ads numeric 10 to the input variable (x). Now the output would increment the numeric 10 to x variable, which was the input parameter on the left-hand side of the Expression.
  • 8.  Aggregate Functions  LINQ Min() Function and Max() Function MIN () function of LINQ is useful to get the minimum value from a collection or list whereas Max () function of LINQ is useful to get the maximum value int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; int m = a.Min(); or int m = a.Max(); From the above syntax, we are getting the minimum and maximum value from the "a" list using the LINQ Min () or Max() function.  LINQ Sum() Function In LINQ sum() function is used to calculate the sum of the items in collections/lists. int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; int sum = a.Sum(); From the above syntax, we are summing up the items in the “a" list using the LINQ Sum function.
  • 9.  LINQ Count() function COUNT () function in LINQ is used to count the number of elements in the list or collection. int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; int m = a.count();  LINQ Aggregate() Function int[] Num = { 1, 2, 3, 4 }; double Average = Num.Aggregate((a, b) => a + b); Output 10 ((1+2)+3)+4 ) in the above syntax, we take two elements 1 and 2 to perform the addition and make 3 then it take the previous result 3 and next element 3 and perform the addition to make the 6 to the next 4 and result will be 10. Ex. Now we will calculate the average of the numbers by applying the Aggregate function. double Average = Num.Aggregate((a, b) => a * b); Output 362880 ((((((((1*2)*3)*4)*5)*6)*7)*8)*9)
  • 10. LINQ Sorting Operator  Sorting Operators in LINQ are used to change the order or sequence of the data (either ascending or descending), which is based on one or more attributes.
  • 11.  LINQ OrderBy Operator(Ascending) In LINQ, the OrderBy operator is used to sort the list/ collection values in ascending order. In if we use order by the operator by default, it will sort the list of values in ascending order. We need to add any ascending condition in the query statement. Ex. var s = Obj.OrderBy(x => x.Name); foreach (var student in s) Console.WriteLine(student.Name);  LINQ OrderBy Descending Operator In LINQ, the OrderBy operator is used to sort the list/ collection values in descending order. Ex. var s = Obj.OrderByDescending (x => x.Name); foreach (var student in s) Console.WriteLine(student.Name);
  • 12.  LINQ ThenBy Operator If we want more than one condition on sorting in LINQ, then we use the ThenBy clause with the OrderBy clause. In LINQ, OrderBy is the primary sorting operator, and ThenBy is the secondary operator. In the above example, we are sorting the "ObjStudent" list item using the multiple fields Name, RoleNumber Id.
  • 13.  LINQ ThenByDescending Operator In LINQ, ThenByDescending operator is used to implement the sorting on multiple fields in the list/ collection, and by default, ThenByDescending operator will sort the list of items in descending order. In LINQ, we use the ThenByDescending operator along with OrderBy operator.
  • 14.  Partition Operators In LINQ, Partition Operators are used to partition the list/collections items into two parts and return one part of the list items. Here are the different types of partitioning operators available in LINQ.
  • 15. Take() and TakeWhile() In LINQ, Take Operator is used to get the specified number of elements in sequence from the list/collection. The LINQ takes the Operator will return the specified number of elements from the starting of collection or list. Ex. string[] countries = { "India", "USA", "Russia", "China", "Australia", "Argentina" }; IEnumerable<string> result = countries.Take(3); foreach (string s in result) Console.WriteLine(s); LINQ, TakeWhile Operator is used to get the elements from the list/collection of the data source as long as the specified condition is holding the expression or until the condition is false. Ex. string[] countries = { "India", "USA", "Russia", "China", "Australia", "Argentina" }; IEnumerable<string> result = (from x in countries select x).TakeWhile(x => x.StartsWith("U")); foreach (string s in result) Console.WriteLine(s);
  • 16. LINQ SKIP OPERATOR In LINQ, the Skip operator is used to skip the specified number of elements from the list/collection and return the remaining elements Ex. string[] countries = { "India", "USA", "Russia", "China", "Australia", "Argentina" }; IEnumerable<string> result = countries.Skip(3); foreach (string s in result) Console.WriteLine(s);