Other meanings of Language Integrated Query
Software Development
Language Integrated Query (LINQ) is a Microsoft .NET component that adds native data querying capabilities to .NET languages, allowing developers to write declarative queries directly within C# and Visual Basic code.1 Introduced with .NET Framework 3.5 in 2007, LINQ provides a consistent, type-safe syntax for querying various data sources, including in-memory collections, XML, and relational databases.2
LINQ is built on a set of extension methods and language features that enable query expressions over any type implementing IEnumerable<T> or IQueryable<T>.1 The standard query operators, such as Where, Select, and OrderBy, are defined in the System.Linq namespace and can be chained to form complex queries. Query syntax in C# resembles SQL, with clauses like from, where, and select, which are translated by the compiler into method calls. This design allows for deferred execution, where queries are not executed until the result is enumerated, enabling efficient composition and lazy evaluation.2
LINQ's extensibility is realized through providers that translate query expressions into native operations for specific data sources. LINQ to Objects operates on in-memory collections, while LINQ to XML (formerly XLinq) provides a streamlined API for querying and transforming XML documents. LINQ to SQL, the first relational provider, maps database tables to .NET classes, and LINQ to Entities (part of ADO.NET Entity Framework) offers a more flexible object-relational mapping. Third-party providers, such as LINQ to Twitter and LINQ to Amazon, demonstrate the breadth of the pattern, though many have become less prominent over time.3
LINQ has had a profound influence on .NET development, promoting a functional programming style and reducing the need for imperative loops. Its introduction coincided with the rise of lambda expressions, anonymous types, and extension methods in C# 3.0, which have become staples of the language. In later versions, LINQ was extended with features like async streams (IAsyncEnumerable<T>) in .NET Core 3.0, and the System.Linq.Async package for reactive queries. The concepts have also inspired similar query capabilities in other languages, such as JavaScript's Array methods and Java's Stream API.4
Beyond the common operators, LINQ includes lesser-known features like Zip, which combines two sequences element-wise, and Aggregate, which applies an accumulator function. The Enumerable.Range and Repeat methods generate sequences lazily, and Cast and OfType handle non-generic collections. LINQ also supports expression trees, which are code-as-data representations that enable providers to analyze and translate queries. A notable edge case is the AsEnumerable method, which forces client-side evaluation of a query, bypassing the provider's translation. Additionally, the IQueryable interface allows for composition of queries across multiple providers, though this can lead to performance pitfalls if not used carefully.5
LINQ has become a fundamental part of the .NET ecosystem, influencing modern C# development and beyond.
Help improve the encyclopedia. Reports go straight to the site manager.