LINQ Introduction - What is LINQ & Why we use LINQ

  Total Views : 685
  Comments : 0
 
  Keywords : Introduction to linq (language integrated query), What is linq in c# / asp.net, Why we need to use linq in c# / asp.net, Why we use linq instead of sql, What is the use of linq in asp.net

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 . It was introduced in .NET 3.5 and we can use it in C# or VB.NET based on our requirements. LINQ can be used to query data from different data sources such as Collections, Generics, XML Documents, ADO.NET Datasets, SQL Databases, Web-service etc. and It connects UI and data access layer.

 

Linq, as it appears in the System.Linq namespace and its a set of extension methods that allow you to query collections directly in code. LINQ is an acronym for "Language Integrated Query". LINQ adds a rich, standardized query syntax in .NET programming languages that allows developers to interact with any type of data.

LINQ Architecture

Following diagram will represent the complete architectural view of linq.

 

LINQ Architectural View Diagram

There are various types of LINQ that we have as shown above in the pictorial representation.

 

  • 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, LINQ is in most cases a significantly more productive querying language than SQL.

 

Also we have benefit of intellisense as linq query is written in code behind and moreover it has full type checking at compile time. So this helps us to avoid runtime errors as we can catch any error in compile time itself. 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.

 

  1. It has full type checking at compile time.
  2. It has intellisense so we can avoid silly errors.
  3. Its query can be reused.
  4. We can debug it using .NET debugger.
  5. It supports filtering, sorting, ordering, grouping with much less effort. 

Disadvantages of LINQ

Following are the drawbacks of using linq in our applications.

 

  1. Since it is written in the code so we cannot make use of Cache execution plan which is a SQL feature as we do in stored procedure.
  2. Writing complex queries in LINQ is a bit tedious as compared to SQL.
  3. If the query is not written properly then performance is degraded.
  4. 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.

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User