SlideShare a Scribd company logo
3
Most read
5
Most read
13
Most read
Language Integrated Query Ch. Vishwa Mohan Freelance Software Consultant & Corporate Trainer
Table of Contents Introducing LINQ New Language Enhancements in C# 3.0 Language Fundamentals Advanced Query Operators in LINQ LINQ to ADO.NET LINQ to XML The Entity Framework
Introducing LINQ What is LINQ ?  Stands for  Language INtegrated Query .  LINQ makes it possible to access different data source with the same syntax.  It is a part of Microsoft .NET Framework 3.5 component.  It adds native data querying capabilities to .NET language using a syntax reminiscent of SQL.  Allows developers to query data structures using SQL-like syntax from within their applications code.  LINQ is another tool for embedding SQL queries into code.  The key feature of LINQ is its integration with widely used programming language, mad possible by the usage of syntax common to all kind of content.  LINQ provides  consistent model for working with data across various kinds of data sources and formats.  In a LINQ query, you are always working with objects. You use the  same basic coding patterns  to query and transform data in XML documents, SQL databases, ADO.NET Datasets, .NET Collections, and any other format for which a LINQ provider is available.
LINQ Basics LINQ is a unified programming model for any kind of data. It can allow the developers to query and manage sequence of items ( Eg:  In memory collections, tables in database, XML Nodes , and so on ).  LINQ enable you to query and manipulate data with a consistent model that is independent from data source (May be  SQL Server, XML file, Arrays or Lists, Text file, e-mail message, SOAP message, etc., ). SQL Like syntax used in LINQ is called “ query expressions ”.  LINQ queries are expressed in the programming language itself, and not as string literals embedded in the application code. So it offers several advantages:  Eliminates the need of using separate language.  With Visual Studio 2008 IDE you will also benefit compile time checking, static typing and Intellisense support.  LINQ to ADO.NET will implements the functionality needs to manipulate the relational data. It has the following modules:  LINQ to SQL, LINQ to DataSet and LINQ to Entity
LINQ Basics
LINQ Basics The LINQ family of technologies provides a consistent query experience for  objects  ( LINQ ),  relational databases  ( LINQ to SQL ) XML  ( LINQ to XML ).
Introducing LINQ All LINQ query operations consists of three distinct operations:  Obtain the data source : int[] mynumbers = new int[] { 49, 28, 20, 15, 25, 23, 24, 10, 7, 34 }; A  LINQ data source  is any object that supports the generic  IEnumerable<T>  interface, or an interface that inherits from it.  Types such as  ArrayList  that support the non-generic  IEnumerable  interface can also be used as a LINQ data source. ( But there is small change in query ) var oddNumbers =  from  int  num  in  mynumbers ..,//specify num type as int. Create the query : var oddNumbers =  from  num  in  mynumbers  where  (num % 2) != 0  select  num;  The  from  clause specifies the data source, the  where  clause applies the filter, and the  select  clause specifies the type of the returned elements.  // oddNumbers  is an  IEnumerable<int> . So you can use  foreach  on this.   Execute the query : foreach (int num in oddNumbers) {Console.Write(&quot;{0,1} &quot;, num); }
Introducing LINQ
LINQ Introduction LINQ query variables are typed as  IEnumerable<T>  or a derived type such as  IQueryable<T> . Let us see the below query  var customerQuery =  from  cust  in  customers  where  cust.City == &quot;London&quot;  select  cust;  Here  var  is a type of  IEnumerable<Customer> . It means that when the query is executed it will produce sequence of zero or more Customer objects.  Types that support  IEnumerable<T>  or a derived interface such as  IQueryable<T>  are called  queryable types . You can create LINQ expression on these types.  The types that implements  IEnumerable  ( Non generic version ) interface also be used as a LINQ data source. (Eg:  ArrayList ).  A queryable type requires no modification or special treatment to serve as a LINQ data source.  If the source data is not already in memory as a queryable type, the LINQ provider must represent it as such.  Eg: LINQ to XML loads an XML document into a queryable  XElement  type: 
LINQ – Language INtegrated Query
LINQ Syntax var   customerQuery =  from  cust  in  customers  where  cust.City == &quot;London&quot;  select  cust;
LINQ Operators Classification
Standard Query Operators in LINQ LINQ query defines a declarative syntax for the most common operators. They are categorized as follow:  Restriction Operators:  where The  where  operator defines the restriction to filter the collection.  Project Operators:  select,  selectMany These  select  and  selectMany  operators are defines a projection to select values of the result based on a selector function.  Ordering Operators:  OrderBy,  OrderByDescending,  ThenBy,    ThenByDescending, Reverse.  The  OrderBy  used to ascending sorting and  OrderByDescending  used for descending sorting.  The  ThenBy  and  TheyByDescending  operators are used for a secondary sort if the first sort gives a similar result.  Reverse  reverses the elements in a collection. In LINQ query expression, you can add several values separated by comma to the  orderby  expression. It takes the  OrderBy()  for first element and  ThenBy()  for the elements that follows.  var myStudents =  from  s  in  students  where  s.Marks >80  orderby   s.Marks ,  s.Age  select  s;
Standard Query Operators in LINQ JOIN Related Operators:  Join, GroupJoin With the  Join  operator a join of two collections can be done. This is similar to  JOIN  in SQL. Grouping Operators:  GroupBy This operator groups a collection with a common key.  Quantifiers:  Any, All, Contains Any  operator defines if any element in the collection satisfies a predicate function.  All  determines if all elements in the collection satisfy a predicate.  Contains  checks whether specific element is in the collection.  Partitioning Operators:  Take, Skip, TakeWhile, SkipWhile .  With these operators you will get a partial result. With  Take , you have to specify the number of elements to take from the collection, whereas the  Skip  ignores the specified number of elements and takes remaining.  The  TakeWhile/SkipWhile  takes/skips the elements as long as a condition is true.
Standard Query Operators in LINQ Set Operators:  Distinct, Union, Intersect, Except All these operators returns a collection set. The  Distinct  operator removes duplications from a collection. The  Union  operator returns unique elements that appear in the given two collections. The  Intersect  return elements that appear in both collections. The  Except  returns elements that appear in just one collection.  Element Operators :  First, FirstOrDefault, Last, LastOrDefault, Single, SingleOrDefault, ElementAt, ElementAtDefault .  All these operators just returns one element.  The  First  operator returns first element that satisfies the condition.  The  FirstOrDefault  is similar to  First , but it returns a default value of the type if the element is not found.  Similarly,  Last  returns the last element that satisfies the condition.  With  ElementAt  operator you can query for specific position element to return. The  Single  returns the only one element that satisfies the condition. If more then one element satisfies the condition an  exception  is thrown.  Aggregate Operators:  Count, Sum, Min, Max, Average, Aggregate
Standard Query Operators in LINQ Conversion Operators:  ToArray, ToEnumerable, ToList, ToDictionary    OfType<T> These operators converts the collections to an  Array, IEnumerable, IList , etc., Generation Operators:  Empty, Range, Repeat These operators returns a new collection. With the  Empty  operator the empty collection is returned. The  Range  operator returns sequence of numbers and  Repeat  returns a collection with one repeated value.  Miscellaneous Operators:  Concat, EqualAll Custom Sequence Operators:  Combine Query Execution:  Deferred, Immediate, QueryReuse
Extending LINQ In Visual Studio 2008 includes LINQ provider assemblies that enable the use of LINQ with  .NET Framework Collections SQL Server Databases  ADO.NET Datasets XML Documents.  LINQ can be extended to support potentially any kind of data store. LINQ provider are being written by third parties for many web services and other database implementations.  Microsoft’s LINQ extensions are:  LINQ to SQL  LINQ to DataSet LINQ to Entities LINQ to XML
LINQ Project You can create any project on .NET Framework version 3.5 supports LINQ.  To enable basic LINQ functionality in your application :  Just reference to  System.Core.dll.  Add  using  directive statement for  System.Linq  to your source code file or project. To enable advanced LINQ functionality  such as expression trees you need add  using  directive statement for  System.Linq.Expressions .  To enable LINQ to XML in your file additionally add  using  directive for  System.Xml.Linq .  To enable LINQ to SQL in your file Add reference to  System.Data.Linq.dll  &  System.Data.dll Add the  System.Data.Linq   namespace reference with  using  directive.  To enable LINQ to DataSet in your file additionally Add reference to  System.Data.DataSetExtensions.dll  &  System.Data.dll Add the  System.Data.Linq   namespace reference.
Visual Studio IDE Support for LINQ.   The Visual Studio 2008 IDE provides the following features that support LINQ application development: Object Relational Designer :  It is a visual design tool that you can use in LINQ to SQL applications to generate classes in C# or VB that represent the relational data in an underlying database.  SQLMetal Command Line Tool:  It is a command-line tool that can be used in build processes to generate classes from existing databases for use in LINQ to SQL applications  LINQ-Aware Code Editors :  Both the C# and Visual Basic code editors support LINQ extensively with new IntelliSense and formatting capabilities.  Debugger Support:  The Visual Studio debugger supports debugging of query expressions.
Thank You !

More Related Content

PPTX
Hibernate ppt
Aneega
 
PPTX
LINQ in C#
Basant Medhat
 
PPTX
Understanding LINQ in C#
MD. Shohag Mia
 
PDF
Java 8 Lambda Expressions & Streams
NewCircle Training
 
PPT
ADO .Net
DrSonali Vyas
 
PDF
Java 8 Lambda Expressions
Scott Leberknight
 
PPTX
ASP.NET Lecture 1
Julie Iskander
 
Hibernate ppt
Aneega
 
LINQ in C#
Basant Medhat
 
Understanding LINQ in C#
MD. Shohag Mia
 
Java 8 Lambda Expressions & Streams
NewCircle Training
 
ADO .Net
DrSonali Vyas
 
Java 8 Lambda Expressions
Scott Leberknight
 
ASP.NET Lecture 1
Julie Iskander
 

What's hot (20)

PPT
C# Exceptions Handling
sharqiyem
 
PDF
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
PPTX
SQL - Structured query language introduction
Smriti Jain
 
PPT
Generics in java
suraj pandey
 
PPTX
Java Servlets
Emprovise
 
PPT
Understanding linq
Anand Kumar Rajana
 
PPTX
Linq to sql
Shivanand Arur
 
PDF
Asp.Net Core MVC , Razor page , Entity Framework Core
mohamed elshafey
 
PPTX
Sql queries presentation
NITISH KUMAR
 
PPTX
Delegates and events in C#
Dr.Neeraj Kumar Pandey
 
PPTX
Web api
Sudhakar Sharma
 
PPT
Jdbc ppt
Vikas Jagtap
 
PPTX
Collections in-csharp
Lakshmi Mareddy
 
PDF
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
PPTX
C# Delegates
Raghuveer Guthikonda
 
PPSX
ADO.NET
Farzad Wadia
 
PPTX
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
PDF
Lambda Expressions in Java
Erhan Bagdemir
 
PPTX
Event In JavaScript
ShahDhruv21
 
PPT
Asp.net.
Naveen Sihag
 
C# Exceptions Handling
sharqiyem
 
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
SQL - Structured query language introduction
Smriti Jain
 
Generics in java
suraj pandey
 
Java Servlets
Emprovise
 
Understanding linq
Anand Kumar Rajana
 
Linq to sql
Shivanand Arur
 
Asp.Net Core MVC , Razor page , Entity Framework Core
mohamed elshafey
 
Sql queries presentation
NITISH KUMAR
 
Delegates and events in C#
Dr.Neeraj Kumar Pandey
 
Jdbc ppt
Vikas Jagtap
 
Collections in-csharp
Lakshmi Mareddy
 
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Edureka!
 
C# Delegates
Raghuveer Guthikonda
 
ADO.NET
Farzad Wadia
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
Lambda Expressions in Java
Erhan Bagdemir
 
Event In JavaScript
ShahDhruv21
 
Asp.net.
Naveen Sihag
 
Ad

Viewers also liked (14)

PPTX
Linq
samneang
 
PPT
Introduccion a LINQ
Tonymx
 
PPT
ILR 101
jasdhillo
 
PPTX
Framework .NET 3.5 10 Linq
Antonio Palomares Sender
 
PPTX
Programación con linq
Gabriel Espinoza Erices
 
PPTX
jQuery
Vishwa Mohan
 
KEY
Introducing LINQ
LearnNowOnline
 
PPT
Module 3: Introduction to LINQ (PowerPoint Slides)
Mohamed Saleh
 
PPTX
LINQ and LINQPad
Andreas Gullberg Larsen
 
PPTX
Task Parallel Library 2014
Lluis Franco
 
PPT
Of Lambdas and LINQ
BlackRabbitCoder
 
PPT
OPC Unified Architecture
Vishwa Mohan
 
PPTX
Syncope
Zareen Kiran
 
Linq
samneang
 
Introduccion a LINQ
Tonymx
 
ILR 101
jasdhillo
 
Framework .NET 3.5 10 Linq
Antonio Palomares Sender
 
Programación con linq
Gabriel Espinoza Erices
 
jQuery
Vishwa Mohan
 
Introducing LINQ
LearnNowOnline
 
Module 3: Introduction to LINQ (PowerPoint Slides)
Mohamed Saleh
 
LINQ and LINQPad
Andreas Gullberg Larsen
 
Task Parallel Library 2014
Lluis Franco
 
Of Lambdas and LINQ
BlackRabbitCoder
 
OPC Unified Architecture
Vishwa Mohan
 
Syncope
Zareen Kiran
 
Ad

Similar to Linq (20)

PPTX
LINQ.pptx
IrfanPinjari2
 
PPT
Linq in C# 3.0: An Overview
pradeepkothiyal
 
PPTX
Think in linq
Sudipta Mukherjee
 
PPT
Linq
ClickExpo
 
DOCX
Linq in C#
Umar Farooq
 
PDF
Module 3: Introduction to LINQ (Material)
Mohamed Saleh
 
PDF
Litwin linq
Jitendra Gangwar
 
PPTX
Asp.net c# mvc Training-Day-5 of Day-9
AHM Pervej Kabir
 
PPT
Language Integrated Query - LINQ
Doncho Minkov
 
PPTX
SQL ttrain wrwrwrw wwrw wwrrrwrwrwrwwrwr.pptx
antony194610
 
PPTX
LINQ PPT.pptx
09AnkitkumarJhariya
 
PPTX
Link quries
ulfat mushtaq
 
PDF
Beginning linq
Shikha Gupta
 
PPT
Language Integrated Query By Nyros Developer
Nyros Technologies
 
PPT
LINQ.ppt
Ponnieaswari M.S
 
PPTX
Introduction to LINQ in UiPath with examples.pptx
shikhartandon9
 
PDF
New c sharp3_features_(linq)_part_v
Nico Ludwig
 
PPTX
ORM - Ivan Marković
Software StartUp Academy Osijek
 
PPTX
Linq
Pranay Rana
 
PDF
New c sharp3_features_(linq)_part_iv
Nico Ludwig
 
LINQ.pptx
IrfanPinjari2
 
Linq in C# 3.0: An Overview
pradeepkothiyal
 
Think in linq
Sudipta Mukherjee
 
Linq
ClickExpo
 
Linq in C#
Umar Farooq
 
Module 3: Introduction to LINQ (Material)
Mohamed Saleh
 
Litwin linq
Jitendra Gangwar
 
Asp.net c# mvc Training-Day-5 of Day-9
AHM Pervej Kabir
 
Language Integrated Query - LINQ
Doncho Minkov
 
SQL ttrain wrwrwrw wwrw wwrrrwrwrwrwwrwr.pptx
antony194610
 
LINQ PPT.pptx
09AnkitkumarJhariya
 
Link quries
ulfat mushtaq
 
Beginning linq
Shikha Gupta
 
Language Integrated Query By Nyros Developer
Nyros Technologies
 
Introduction to LINQ in UiPath with examples.pptx
shikhartandon9
 
New c sharp3_features_(linq)_part_v
Nico Ludwig
 
ORM - Ivan Marković
Software StartUp Academy Osijek
 
New c sharp3_features_(linq)_part_iv
Nico Ludwig
 

More from Vishwa Mohan (13)

PPT
WPF
Vishwa Mohan
 
PPT
Wwf
Vishwa Mohan
 
PDF
Da package usersguide
Vishwa Mohan
 
PDF
Dareadme
Vishwa Mohan
 
PPTX
CSharp Presentation
Vishwa Mohan
 
PPTX
Uml
Vishwa Mohan
 
PPT
Xml
Vishwa Mohan
 
PPT
Real Time Systems &amp; RTOS
Vishwa Mohan
 
PPT
Embedded Linux
Vishwa Mohan
 
PPT
Introduction To Embedded Systems
Vishwa Mohan
 
PPT
Microsoft.Net
Vishwa Mohan
 
PPT
Zig Bee
Vishwa Mohan
 
PPT
WCF
Vishwa Mohan
 
Da package usersguide
Vishwa Mohan
 
Dareadme
Vishwa Mohan
 
CSharp Presentation
Vishwa Mohan
 
Real Time Systems &amp; RTOS
Vishwa Mohan
 
Embedded Linux
Vishwa Mohan
 
Introduction To Embedded Systems
Vishwa Mohan
 
Microsoft.Net
Vishwa Mohan
 
Zig Bee
Vishwa Mohan
 

Linq

  • 1. Language Integrated Query Ch. Vishwa Mohan Freelance Software Consultant & Corporate Trainer
  • 2. Table of Contents Introducing LINQ New Language Enhancements in C# 3.0 Language Fundamentals Advanced Query Operators in LINQ LINQ to ADO.NET LINQ to XML The Entity Framework
  • 3. Introducing LINQ What is LINQ ? Stands for Language INtegrated Query . LINQ makes it possible to access different data source with the same syntax. It is a part of Microsoft .NET Framework 3.5 component. It adds native data querying capabilities to .NET language using a syntax reminiscent of SQL. Allows developers to query data structures using SQL-like syntax from within their applications code. LINQ is another tool for embedding SQL queries into code. The key feature of LINQ is its integration with widely used programming language, mad possible by the usage of syntax common to all kind of content. LINQ provides consistent model for working with data across various kinds of data sources and formats. In a LINQ query, you are always working with objects. You use the same basic coding patterns  to query and transform data in XML documents, SQL databases, ADO.NET Datasets, .NET Collections, and any other format for which a LINQ provider is available.
  • 4. LINQ Basics LINQ is a unified programming model for any kind of data. It can allow the developers to query and manage sequence of items ( Eg: In memory collections, tables in database, XML Nodes , and so on ). LINQ enable you to query and manipulate data with a consistent model that is independent from data source (May be SQL Server, XML file, Arrays or Lists, Text file, e-mail message, SOAP message, etc., ). SQL Like syntax used in LINQ is called “ query expressions ”. LINQ queries are expressed in the programming language itself, and not as string literals embedded in the application code. So it offers several advantages: Eliminates the need of using separate language. With Visual Studio 2008 IDE you will also benefit compile time checking, static typing and Intellisense support. LINQ to ADO.NET will implements the functionality needs to manipulate the relational data. It has the following modules: LINQ to SQL, LINQ to DataSet and LINQ to Entity
  • 6. LINQ Basics The LINQ family of technologies provides a consistent query experience for objects ( LINQ ), relational databases ( LINQ to SQL ) XML ( LINQ to XML ).
  • 7. Introducing LINQ All LINQ query operations consists of three distinct operations: Obtain the data source : int[] mynumbers = new int[] { 49, 28, 20, 15, 25, 23, 24, 10, 7, 34 }; A LINQ data source is any object that supports the generic IEnumerable<T> interface, or an interface that inherits from it. Types such as ArrayList that support the non-generic IEnumerable interface can also be used as a LINQ data source. ( But there is small change in query ) var oddNumbers = from int num in mynumbers ..,//specify num type as int. Create the query : var oddNumbers = from num in mynumbers where (num % 2) != 0 select num; The from clause specifies the data source, the where clause applies the filter, and the select clause specifies the type of the returned elements. // oddNumbers is an IEnumerable<int> . So you can use foreach on this. Execute the query : foreach (int num in oddNumbers) {Console.Write(&quot;{0,1} &quot;, num); }
  • 9. LINQ Introduction LINQ query variables are typed as IEnumerable<T> or a derived type such as IQueryable<T> . Let us see the below query var customerQuery = from cust in customers where cust.City == &quot;London&quot; select cust; Here var is a type of IEnumerable<Customer> . It means that when the query is executed it will produce sequence of zero or more Customer objects. Types that support IEnumerable<T> or a derived interface such as IQueryable<T> are called queryable types . You can create LINQ expression on these types. The types that implements IEnumerable ( Non generic version ) interface also be used as a LINQ data source. (Eg: ArrayList ). A queryable type requires no modification or special treatment to serve as a LINQ data source. If the source data is not already in memory as a queryable type, the LINQ provider must represent it as such. Eg: LINQ to XML loads an XML document into a queryable  XElement  type: 
  • 10. LINQ – Language INtegrated Query
  • 11. LINQ Syntax var customerQuery = from cust in customers where cust.City == &quot;London&quot; select cust;
  • 13. Standard Query Operators in LINQ LINQ query defines a declarative syntax for the most common operators. They are categorized as follow: Restriction Operators: where The where operator defines the restriction to filter the collection. Project Operators: select, selectMany These select and selectMany operators are defines a projection to select values of the result based on a selector function. Ordering Operators: OrderBy, OrderByDescending, ThenBy, ThenByDescending, Reverse. The OrderBy used to ascending sorting and OrderByDescending used for descending sorting. The ThenBy and TheyByDescending operators are used for a secondary sort if the first sort gives a similar result. Reverse reverses the elements in a collection. In LINQ query expression, you can add several values separated by comma to the orderby expression. It takes the OrderBy() for first element and ThenBy() for the elements that follows. var myStudents = from s in students where s.Marks >80 orderby s.Marks , s.Age select s;
  • 14. Standard Query Operators in LINQ JOIN Related Operators: Join, GroupJoin With the Join operator a join of two collections can be done. This is similar to JOIN in SQL. Grouping Operators: GroupBy This operator groups a collection with a common key. Quantifiers: Any, All, Contains Any operator defines if any element in the collection satisfies a predicate function. All determines if all elements in the collection satisfy a predicate. Contains checks whether specific element is in the collection. Partitioning Operators: Take, Skip, TakeWhile, SkipWhile . With these operators you will get a partial result. With Take , you have to specify the number of elements to take from the collection, whereas the Skip ignores the specified number of elements and takes remaining. The TakeWhile/SkipWhile takes/skips the elements as long as a condition is true.
  • 15. Standard Query Operators in LINQ Set Operators: Distinct, Union, Intersect, Except All these operators returns a collection set. The Distinct operator removes duplications from a collection. The Union operator returns unique elements that appear in the given two collections. The Intersect return elements that appear in both collections. The Except returns elements that appear in just one collection. Element Operators : First, FirstOrDefault, Last, LastOrDefault, Single, SingleOrDefault, ElementAt, ElementAtDefault . All these operators just returns one element. The First operator returns first element that satisfies the condition. The FirstOrDefault is similar to First , but it returns a default value of the type if the element is not found. Similarly, Last returns the last element that satisfies the condition. With ElementAt operator you can query for specific position element to return. The Single returns the only one element that satisfies the condition. If more then one element satisfies the condition an exception is thrown. Aggregate Operators: Count, Sum, Min, Max, Average, Aggregate
  • 16. Standard Query Operators in LINQ Conversion Operators: ToArray, ToEnumerable, ToList, ToDictionary OfType<T> These operators converts the collections to an Array, IEnumerable, IList , etc., Generation Operators: Empty, Range, Repeat These operators returns a new collection. With the Empty operator the empty collection is returned. The Range operator returns sequence of numbers and Repeat returns a collection with one repeated value. Miscellaneous Operators: Concat, EqualAll Custom Sequence Operators: Combine Query Execution: Deferred, Immediate, QueryReuse
  • 17. Extending LINQ In Visual Studio 2008 includes LINQ provider assemblies that enable the use of LINQ with .NET Framework Collections SQL Server Databases ADO.NET Datasets XML Documents. LINQ can be extended to support potentially any kind of data store. LINQ provider are being written by third parties for many web services and other database implementations. Microsoft’s LINQ extensions are: LINQ to SQL LINQ to DataSet LINQ to Entities LINQ to XML
  • 18. LINQ Project You can create any project on .NET Framework version 3.5 supports LINQ. To enable basic LINQ functionality in your application : Just reference to System.Core.dll. Add using directive statement for System.Linq to your source code file or project. To enable advanced LINQ functionality such as expression trees you need add using directive statement for System.Linq.Expressions . To enable LINQ to XML in your file additionally add using directive for System.Xml.Linq . To enable LINQ to SQL in your file Add reference to System.Data.Linq.dll & System.Data.dll Add the System.Data.Linq namespace reference with using directive. To enable LINQ to DataSet in your file additionally Add reference to System.Data.DataSetExtensions.dll & System.Data.dll Add the System.Data.Linq namespace reference.
  • 19. Visual Studio IDE Support for LINQ. The Visual Studio 2008 IDE provides the following features that support LINQ application development: Object Relational Designer : It is a visual design tool that you can use in LINQ to SQL applications to generate classes in C# or VB that represent the relational data in an underlying database. SQLMetal Command Line Tool: It is a command-line tool that can be used in build processes to generate classes from existing databases for use in LINQ to SQL applications LINQ-Aware Code Editors : Both the C# and Visual Basic code editors support LINQ extensively with new IntelliSense and formatting capabilities. Debugger Support: The Visual Studio debugger supports debugging of query expressions.

Editor's Notes

  • #3: Th
  • #4: Language Integrated Query ( LINQ , pronounced &amp;quot;link&amp;quot;) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages using a syntax reminiscent of SQL. Many of the concepts that LINQ has introduced were originally tested in Microsoft&apos;s Cω research project. LINQ was released as a part of .NET Framework 3.5 on November 19, 2007. LINQ is available for any .NET languages. Through visual Studio you can find support for C#, VB.NET. LINQ is a uniform programming model for any kind of data it introduces queries as first class concept in any .NET languages.
  • #5: You can write LINQ queries against various enumerable data sources (that is, a data source that implements the IEnumerable interface). Examples are in-memory data structures (Collections, Lists, etc.,), XML documents, SQL databases, and  DataSet objects. LINQ to SQ L: Allows to querying a relational structure by converting LINQ query into a native SQL Query. LINQ to Dataset : Interacts with data already in ADO.NET DataSet structures. LINQ to Entity : To query a logical model that usually has a higher-level representation of data information compared to direct access to relational data sources. When LINQ query operates on data that is on relational database, the LINQ query generates an equivalent SQL statements.
  • #8: The above query can be applied to SQL Database , DataSet, or an array of objects in memory or many other kinds of data. Here Customer could be a collection of objects. The SQL like syntax in LINQ called as query expressions . The reason to start with a from clause instead of a select statement, as in SQL syntax, is related to the need to provide Microsoft IntelliSense capabilities within the remaining part of the query, which makes writing conditions, selections, and any other LINQ query clauses easier.
  • #11: At the core, LINQ works over anything that implements IEnumerable . Natively includes a number of lists that are part of the .NET Framework as well as lists you create. It also works with lists of elements and attributes present in XML documents as well as fields and tables present in DataSets. By extending the base IEnumerable with a new interface, IQueryable , we can add a layer which retains the query structure and has the ability to translate it into a language more native to the underlying data source (like TSQL for SQL Server). Out of the box, the .NET Framework ships with two such providers: LINQ to SQL and LINQ to Entities.
  • #14: The where query operator defines the restriction to filter the collection. The Orderxx operators are used for sorting. ThenBy and ThenByDescending operators are used for a secondary sort if the first sort gives similar result.
  • #15: The where query operator defines the restriction to filter the collection. The Orderxx operators are used for sorting. ThereBy and ThereByDescending operators are used for a secondary sort if the first sort gives similar result.
  • #18: Add some more stuff on Extending LINQ (CVM)