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.
Bạn đang xem: Linq c# là gì
What is LINQ
The full size of LINQ is "Language Integrated Query," and introduced in .NET Framework 3.5 lớn query the data from different sources of data such as collections, generics, XML documents, ADO.NET Datasets, Squốc lộ, Web Services, etc. in C# and VB.NET. LINQ provides the rich, standardized query syntax in a .NET programming language such as C# & VB.NET, which allows the developers to lớn 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 lớn 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 & the underlying data source, there is another component also present, known as LINQProvider.
The responsibility of the LINQ provider is lớn convert the LINQ Query inlớn 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 Squốc lộ Database. In this case, LINQ Query will fit inlớn the LINQ khổng lồ Squốc lộ Provider. In this case, it will convert the LINQ Query inlớn T-SQL so that the underlying database can understvà in the same way if there is a need lớn fetch the data from the XML document. We will use the same LINQ query in this case as well, which is LINQ lớn XML Provider. XML provider would convert the LINQ query into XLST so that the XMLDataSource can underst&.
As we mentioned in the above sầu diagram, we have sầu different types of LINQ Objects available in C# & VB.NET.
Need of LINQ
LINQ is simpler, ordered, and higher-level than SQL. When we want khổng lồ use Querying Database, in most cases, LINQ is a more productive sầu query language than Squốc lộ.
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 lớn write the query in LINQ is more fun.
Here, we are taking an example of developing a .NET application, & that application requires data from different data sources.Suppose the application needs the data from Squốc lộ Server Database. So, as a developer, to lớn access the data from SQL Server Database, we need lớn understvà ADO.NET và Squốc lộ Server-specific syntaxes. If the database is Oracle, then there is a need to understvà the Squốc lộ Syntax, which is specific to Oracle Database.The application also needs the data from an XML document. So, as a developer khổng lồ work with an XML document, we need khổng lồ understvà the XSLT & XPath queries. In the application, there is also a need to manipulate the data (objects) in memory such as List, List, etc. So, as a developer, there is a need to lớn understand how lớn work with in-memory objects.
LINQ provides the Unikhung Programming Model (i.e., familiar query syntax). It allows us to lớn work with different data sources by using a standard, or in a unified coding style. Hence, we don"t require to lớn learn the different syntaxes to lớn 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:We bởi not need khổng lồ learn new query language syntaxes for different sources of data because it provides the standard query syntax for the various data sources.In LINQ, we have sầu to lớn write the Less code in comparison khổng lồ the traditional approach. With the use of LINQ, we can minimize the code.LINQ provides the compile-time error checking as well as intelligence support in Visual Studio. This powerful feature helps us to lớn avoid run-time errors.LINQ provides a lot of built-in methods that we can be used lớn perform the different operations such as filtering, ordering, grouping, etc. which makes our work easy.The query of LINQ can be reused.
Disadvantages of LINQ
Disadvantages of LINQ are:With the use of LINQ, it"s very difficult to write a complex query lượt thích SQL.It was written in the code, & we cannot make use of the Cabịt Execution plan, which is the Squốc lộ feature as we bởi in the stored procedure.If the query is not written correctly, then the performance will be degraded.If we make some changes to lớn our queries, then we need lớn recompile the application và need to lớn redeploy the dll to lớn the server.