Header add

In this article we will learn
  • What is LINQ  ?
  • Why we use LINQ  ?
  • LINQ Architecture
  • Advantage of LINQ  ?
  • Diadvantage of LINQ  ?
  • Types of LINQ  ?
What is LINQ ?

LINQ stands for "Language Integrated Query" and pronounced as "LINK". LINQ was introduced in in Visual Studio 2008 with .NET Framework 3.5 of C# 3.0 and VB.NET 2008 (VB 9.0). It enables you to query the data from the various data sources like SQL databases, XML documents, ADO.NET Datasets, Web services and any other objects such as Collections, Generics etc. by using a SQL Query like syntax with .NET framework languages like C# and VB.NET.

Why we use LINQ ?

  • LINQ enables us to work with different data sources using similar types of code styles like SQL Database,XMLDocuments, and in-memory objects. Another benefit of using LINQ is that it provides intellisense and compile time error checking.
  • LINQ has full type checking at compile-time and Intelligent support in Visual Studio, since it used the .NET framework languages like C# and VB.NET.This powerful feature helps you to avoid run-time errors.
  • LINQ also provides a uniform programming model (i.e. common query syntax) to query various data sources. Hence you don’t need to learn the different ways to query different data sources.
  • System.Linq namespace is necessary for writing LINQ queries and to implement it.
LINQ Architecture 

This is the architecture for LINQ; we all know that we can develop .NET application. Similarly, LINQ programming returns any of the above mentioned .NET programming languages. Between the actual LINQ query and underlying data source there is another component called LINQ provider. The responsibility of this LINQ provider is to convert this LINQ query into a format so that the underlying data source can understand it.

Let's say the application is trying to fetch data from a SQL database; if that is the case, this LINQ query will fit into the LINQ to SQL provider which is going to convert this LINQ query into T-SQL so that the underlying database can understand. Similarly, if the LINQ query has to fetch data from XML Documents the same LINQ query is going to be fed into this, which is LINQ to XML provider, which is going to convert this LINQ query into XLST so that the XML datasource can understand it.

Advantages of LINQ

  • Linq provides a uniform programming model to query data sources (like SQL databases, XML documents, ADO.NET Datasets, Various Web services and any other objects such as Collections, Generics etc.).
  • It has full type checking at compile-time and IntelliSense support in Visual Studio. This powerful feature helps you to avoid run-time errors.
  • It supports various powerful features like filtering, ordering and grouping with minimum code.
  • Its Query can be reused.
  • It also allows debugging through .NET debugger.
Disadvantages of LINQ

  • LINQ is not good to write complex queries like SQL.
  • LINQ doesn’t take the full advantage of SQL features like cached execution plan for stored procedure.
  • Performance is degraded if you don't write the LINQ query correctly.
  • If you have done some changes in your query, you have to recompile it and redeploy its dll to the server.
LINQ Types

LINQ to Objects
It provides the facility to query any kind of C# in-memory objects, like as arrays, lists, generic list and other collection types.LINQ to object query returns IEnumerable collection. It provides a new approach to query collection with powerful filtering, ordering and grouping capablities with minimum code.
LINQ to Ado.Net
LINQ to ADO.NET includes different flavors of LINQ to query data from different databases like as Microsoft SQL Server, Oracle, and others. It has following flavours
It is specifically designed for working with Sql Server database. It provides run-time infrastructure for managing relational data as objects. It also supports transactions, views and stored procedures. It is an object-relational mapping (ORM) framework that allow 1-1 mapping of Sql Server database to .net classes. In this mapping the classes that match the database table are created automatically from the database itself and we can use these classes immediately.
LINQ to DataSet
It is an easy and faster way to query data cached in a DataSet object. It also allow LINQ to query over any database that can be query with Ado.Net.
LINQ to Entities
In many ways it is very similar to LINQ to SQL. It uses a conceptual Entity Data Model (EDM). The ADO.NET Entity Framework has been improved in .NET framework 4.0 to query any database like Sql Server, Oracle, MySql, DB2 and many more.
It provides an improved XML programming interface. Using this we can query, modify xml document and also save document after modification. System.Xml.Linq namespace contains classes for LINQ to XML.
PLINQ (Parallel LINQ)
PLINQ was introduced in .Net framework 4.0. It extends LINQ to Objects with a new parallel programming library. Using this, we can break/split up a query to execute simultaneously/parallel on different processors.

    In this tutorial we discussed Introduction to LINQ. If have any question related to this topic then give your feedback.

Post a Comment

Previous Post Next Post