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

Similar to LINQ.pptx

Understanding linq
Understanding linqUnderstanding linq
Understanding linq
Anand Kumar Rajana
 
Intake 37 linq2
Intake 37 linq2Intake 37 linq2
Intake 37 linq2
Mahmoud Ouf
 
How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1
Taisuke Oe
 
Linq in C#
Linq in C#Linq in C#
Linq in C#
Umar Farooq
 
Mysqlppt
MysqlpptMysqlppt
Vizwik Coding Manual
Vizwik Coding ManualVizwik Coding Manual
Vizwik Coding Manual
Vizwik
 
Functional programming 101
Functional programming 101Functional programming 101
Functional programming 101
Maneesh Chaturvedi
 
Mysqlppt
MysqlpptMysqlppt
Intake 37 linq3
Intake 37 linq3Intake 37 linq3
Intake 37 linq3
Mahmoud Ouf
 
Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2
José Paumard
 
Python cheatsheet Indian Servers
Python cheatsheet Indian ServersPython cheatsheet Indian Servers
Python cheatsheet Indian Servers
Indian Servers
 
Intake 38 data access 3
Intake 38 data access 3Intake 38 data access 3
Intake 38 data access 3
Mahmoud Ouf
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
Olexandra Dmytrenko
 
Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03
Avelin Huo
 
Python_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptxPython_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptx
SahajShrimal1
 
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docxAssg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
festockton
 
Linq in C# 3.0: An Overview
Linq in C# 3.0: An OverviewLinq in C# 3.0: An Overview
Linq in C# 3.0: An Overview
pradeepkothiyal
 
Basics of Functional Programming
Basics of Functional ProgrammingBasics of Functional Programming
Basics of Functional Programming
Sartaj Singh
 
ORM - Ivan Marković
ORM - Ivan MarkovićORM - Ivan Marković
ORM - Ivan Marković
Software StartUp Academy Osijek
 
UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4
DianaGray10
 

Similar to LINQ.pptx (20)

Understanding linq
Understanding linqUnderstanding linq
Understanding linq
 
Intake 37 linq2
Intake 37 linq2Intake 37 linq2
Intake 37 linq2
 
How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1
 
Linq in C#
Linq in C#Linq in C#
Linq in C#
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Vizwik Coding Manual
Vizwik Coding ManualVizwik Coding Manual
Vizwik Coding Manual
 
Functional programming 101
Functional programming 101Functional programming 101
Functional programming 101
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Intake 37 linq3
Intake 37 linq3Intake 37 linq3
Intake 37 linq3
 
Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2
 
Python cheatsheet Indian Servers
Python cheatsheet Indian ServersPython cheatsheet Indian Servers
Python cheatsheet Indian Servers
 
Intake 38 data access 3
Intake 38 data access 3Intake 38 data access 3
Intake 38 data access 3
 
Functional Programming
Functional ProgrammingFunctional Programming
Functional Programming
 
Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03Designing A Syntax Based Retrieval System03
Designing A Syntax Based Retrieval System03
 
Python_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptxPython_Unit-1_PPT_Data Types.pptx
Python_Unit-1_PPT_Data Types.pptx
 
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docxAssg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
 
Linq in C# 3.0: An Overview
Linq in C# 3.0: An OverviewLinq in C# 3.0: An Overview
Linq in C# 3.0: An Overview
 
Basics of Functional Programming
Basics of Functional ProgrammingBasics of Functional Programming
Basics of Functional Programming
 
ORM - Ivan Marković
ORM - Ivan MarkovićORM - Ivan Marković
ORM - Ivan Marković
 
UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4
 

Recently uploaded

みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
jpupo2018
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 

Recently uploaded (20)

みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 

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);