What is LINQ?

LINQ is a set of features that extends powerful query capabilities to the language syntax of C#. LINQ introduces standard, easily-learned patterns for querying and updating data, and the technology can be extended to support potentially any kind of data store. The .NET Framework includes LINQ provider assemblies that enable the use of LINQ with .NET Framework collections, SQL Server databases, ADO.NET Datasets, and XML documents.

Language-Integrated Query (LINQ) is an innovation introduced in the .NET Framework version 3.5 that bridges the gap between the world of objects and the world of data.

Traditionally, queries against data are expressed as simple strings without type checking at compile time or IntelliSense support. Furthermore, you have to learn a different query language for each type of data source: SQL databases, XML documents, various Web services, and so on. LINQ makes a query a first-class language construct in C#. You write queries against strongly typed collections of objects by using language keywords and familiar operators.

You can write LINQ queries in C# for SQL Server databases, XML documents, ADO.NET Datasets, and any collection of objects that supports IEnumerable or the generic IEnumerable<T> interface. LINQ support is also provided by third parties for many Web services and other database implementations.


You can write LINQ query either with C#-integrated LINQ expression syntax or with explicit syntax using extension methods.

LINQ expression syntax:

IEnumerable<string> query = from s in names
                            where s.Length == 5
                            orderby s
                            select s.ToUpper();

Explicit syntax using extension methods:

IEnumerable<string> query = names.Where(s => s.Length == 5)
                                 .OrderBy(s => s)
                                 .Select(s => s.ToUpper());

Results are identical in both cases. LINQ expression syntax is just "syntactic sugar" which will be converted to code which uses extension LINQ methods during compilation.

Short answer

  • LINQ introduces standard, easily-learned patterns for querying and updating data.
  • You can use LINQ for querying Objects (with IEnumerable<T> interface), XML, SQL, ADO.NET datasets.
  • You can write LINQ queries either with LINQ expressions syntax (similar to SQL queries) or with explicit syntax using extensions methods.

Similar articles