Here, we will learn the introduction of LINQ, what is the LINQ in C#/asp.net, why we use LINQ in C#/asp.net, LINQ architecture, Advantage and Disadvantage of LINQ.
What is LINQ
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.
This is the architecture of the LINQ, as we know that we can develop the application in .NET. Similarly, the LINQ programming can return the any above mentioned .NET programming language. Between the actual LINQ query and the underlying data source, there is another component also present, known as LINQProvider.
The responsibility of the LINQ provider is to convert the LINQ Query into a format so that the data source can understand it.
Example: Here, we will take a scenario, let us say the application wants to fetch the data from SQL Database. In this case, LINQ Query will fit into the LINQ to SQL Provider. In this case, it will convert the LINQ Query into T-SQL so that the underlying database can understand in the same way if there is a need to fetch the data from the XML document. We will use the same LINQ query in this case as well, which is LINQ to XML Provider. XML provider would convert the LINQ query into XLST so that the XMLDataSource can understand.
As we mentioned in the above diagram, we have different types of LINQ Objects available in C# and VB.NET.
Need of LINQ
LINQ is simpler, ordered, and higher-level than SQL. When we want to use Querying Database, in most cases, LINQ is a more productive query language than SQL.
Also, we have the benefits of IntelliSense as the LINQ query is written in behind the code. LINQ has full type checking at compile time so that we can catch any error in compile time itself. In C# or VB.Net to write the query in LINQ is more fun.
Here, we are taking an example of developing a .NET application, and that application requires data from different data sources.
LINQ provides the Uniform Programming Model (i.e., familiar query syntax). It allows us to work with different data sources by using a standard, or in a unified coding style. Hence, we don't require to learn the different syntaxes to query for various data sources.
LINQ also has some Advantages and Disadvantages as well they are:
Advantages of LINQ
In our applications, the benefits of LINQ are:
Disadvantages of LINQ
Disadvantages of LINQ are: