Here we will learn introduction to linq, what is linq in c# / asp.net, why we use linq in c# / asp.net, linq architecture with diagram, advantages of linq, disadvantages of linq.
What is LINQ?
The full form of LINQ is Language Integrated Query
and it was introduced in .NET Framework 3.5 to query the data from different data sources such as collections, generics, XML Documents, ADO.NET Datasets, SQL, Web Service, etc. in C# and VB.NET. The LINQ will provide a rich, standardized query syntax in .NET programming languages such as C# and VB.NET to allow the developers to interact with any type of data.
In c# or vb.net, the LINQ functionality can be achieved by importing System.Linq
namespace in our application. Generally, the LINQ will contain a set of extension methods that allow you to query the data source objects directly in the code based on our requirements.
LINQ Architecture
Following diagram will represent the complete architectural view of LINQ.
As mentioned in the above diagram following are the various types of LINQ objects available in c# and vb.net.
- LINQ to Objects
- LINQ to Datasets
- LINQ to SQL
- LINQ to Entities
- LINQ to XML
We would be covering these topics in detail in the later part of the series.
Why we need to use LINQ?
Now the question arise why should we use LINQ? What’s so different in LINQ that everyone would want to use it in their application and not the SQL? Well the answer is quite simple as LINQ is simpler, tidier, and higher-level than SQL. When it comes to querying databases, In most cases, LINQ is more productive querying language than SQL.
Also we have the benefit of intellisense as LINQ query is written in code behind and moreover it has full type checking at compile time so we can catch any error in compile time itself. In c# or vb.net writing queries is more fun in LINQ but it has its advantages as well as disadvantages which are as follows:
Advantages of LINQ
Following are the advantages of using LINQ in our applications.
- It has full type checking at compile time.
- It has intellisense, so we can avoid silly errors.
- Its query can be reused.
- We can debug it using .NET debugger.
- It supports filtering, sorting, ordering, grouping with much less effort.
Disadvantages of LINQ
Following are the drawbacks of using LINQ in our applications.
- Since it was written in the code we cannot make use of Cache execution plan which is a SQL feature as we do in stored procedure.
- Writing complex queries in LINQ is a bit tedious as compared to SQL.
- If the query is not written properly then performance is degraded.
- We have to build the project and deploy the DLL every time some change is done in the query.
LINQ has its own advantages and disadvantages so based on requirements we can use linq in our applications.
0 Comments