Introduction
- LINQ is a new technology introduced in .NET 3.5
- LINQ is acronym for Language Integrated Query
- The LINQ feature is one of the major differences between the .NET 3.0 and .NET 3.5 frameworks
- LINQ is designed to fill the gap that exists between traditional .NET, that offers strong typing, and a full Object-Oriented approach
LINQ introduces an easy-learning approach for querying and modifying data and can support querying various types of data sources including relational data, XML and in-memory data structures.
Advantages of Using LINQ
LINQ offers the following advantages:
- LINQ offers a common syntax for querying any type of data sources
- Secondly, it binds the gap between relational and object-oriented approachs
- LINQ expedites development time by catching errors at compile time and includes IntelliSense & Debugging support
- LINQ expressions are Strongly Typed.
What we mean by Strongly Typed?
Strongly typed expressions ensure access to values as the correct type at compile time & prevents type mismatch errors being caught when the code is compiled rather at run-time.
Core Assemblies in LINQ
The core assemblies in LINQ are:
- using System.Linq
Provides Classes & Interface to support LINQ Queries - using System.Collections.Generic
Allows the user to create Strongly Typed collections that provide type safety and performance (LINQ to Objects) - using System.Data.Linq
Provides the functionality to access relational databases (LINQ to SQL) - using System.Xml.Linq
Provides the functionality for accessing XML documents using LINQ (LINQ to XML) - using System.Data.Linq.Mapping
Designates a class as an entity associated with a database.
Types of LINQ
LINQ provides three basic types of queries, each type offers specific functionality and is designed to query a specific source. The three basic types of queries are:
- LINQ to Objects
- LINQ to XML(or XLINQ)
- LINQ to SQL(or DLINQ)
Let us briefly discuss each of them.
LINQ to Objects
- LINQ to Object is the basics of LINQ
- It enables us to perform complex query operations against any enumerable object (object that supports the IEnumerable interface)
LINQ queries provide the following advantages over traditional foreach loops:
- They are more concise & readable, especially when filtering multiple conditions
- Provides powerful filtering, grouping and ordering with little coding