Home > DeveloperSection > Articles > LINQ (Language Integrated Query)

LINQ (Language Integrated Query)

Posted by  Amit Singh
on    November-27-2010 20:53 PM

LINQ LINQ 
Ratings:
1 Comment(s)
 6368  View(s)
Rate this:

LINQ (Language Integrated Query)

LINQ is a set of extensions to the .NET Framework that encompass language-integrated query, set, and transform operations. It extends C# and Visual Basic with native language syntax for queries and provides class libraries to take advantage of these capabilities.

In LINQ we used same format as SQL but some difference like positioning, style in Select, where etc. We use the System.Linq namespace.

Benefits of LINQ:

It provides rich Meta data.

Compile-time syntax checking

LINQ is static typing and provide intelliSence (previously available in imperative code).

It provides query in concise way.

 

We create LINQ between LINQ to object, LINQ to XML, LINQ to SQL.

 

 LINQ to objects

The term "LINQ to Objects" refers to the use of LINQ queries with any IEnumerable or  IEnumerable <T> collection directly, without the use of an intermediate LINQ provider or API such as or LINQ to XML, LINQ to SQL.

 

LINQ to SQL.

In Linq to sql , it changes into object model and sends to database for execution. After execution it find the result. So we easily maintain the relational database like query.

 

LINQ to XML

LINQ to XML provides an easy query interface for xml files. We do with linq to xml to read and write data from/to xml file, using the file for persistency maintaining a list of objects. Linq to xml can be used for storing application settings, storing persistent objects or any other data needs to be saved.

How use the LINQ in our program

Step1: we open the console application and write these codes

 

using System.Collections.Generic;

using System.Linq;

string[] Country = { "India", "SriLanka", "China",                       "Nepal", "Newzeland", "South Africa","America", "England" };

 

//In this section using LINQ Query

IEnumerable<string> query = from s in Country

                            where s.Length == 5

                            orderby s                 

                            select s.ToUpper();

 

foreach (string item in query)

Console.WriteLine(item);

 

Step2:Run it

 

Output:

India

China

Nepal

 


LINQ

By John Smith on   3 years ago
Good One!















Recent Activities


Barbara Jones added new Question What is ANR?   3 days ago

Kamlakar Singh added new Blog Convert Text Document to PDF File   17 days ago

Kamlakar Singh added new Article Introduction to Backbone.js   17 days ago

Don't want to miss updates? Please click the below button!