What’s a built-in query in a language?

Print anything with Printful



LINQ integrates declarative query syntax into C# and VB.NET, solving problems faced by developers querying relational databases or XML documents. It provides SQL-like syntax for querying .NET collections and eliminates the need for built-in query languages. LINQ depends on components called providers to perform data mapping. A library of query operators added to the .NET Framework performs tasks such as filtering, sorting, set theory operations, and aggregation.

LINQ (Language Integrated query) provides the ability to seamlessly integrate declarative query syntax into imperative languages, primarily C# and VB.NET. The development of LINQ solved the problems encountered by developers working in object-oriented environments when executing queries. It was introduced as part of Microsoft® .NET Framework version 3.5 in November 2007 and in the Visual Studio® code name “Orcas”.

Prior to building language-integrated queries, .NET languages ​​did not have a native way to query relational databases or XML documents. Developers writing in these languages ​​had to embed SQL or XQuery respectively as strings and manually map the resulting data to .NET objects. Query strings and built-in mappings cannot be validated by .NET compilers, allowing for potential run-time error detection.

Another problem that developers faced before language built-in query was that .NET languages ​​only had object-oriented syntax for querying collections of .NET objects. Typically, the developer iterates through an entire collection of sources, building new collections of results based on search criteria. The developer could also transform the data when creating the result collections. This approach was cumbersome; a simple select query written in C# or VB would require at least five lines of code, while the same query would require one line of code in a query language.

The challenges of executing queries within an object-oriented environment gave Microsoft the impetus to create LINQ. LINQ provides SQL-like query syntax for use in line with C# or VB, complete with static type checking. When querying .NET collections, instead of using nested loops, developers can use LINQ syntax to select items and transform data. Among other benefits, this results in fewer lines of code than purely object-oriented syntax.

When accessing external data sources, LINQ and its supporting components eliminate the need for built-in query languages ​​and data mappings within a .NET language itself. To perform data mapping, LINQ depends on components called LINQ providers. LINQ-to-Objects is the stock provider that allows LINQ to access .NET collections. Similarly, there are providers to access relational databases and XML documents. Most of these providers are third-party components not included in the .NET Framework. Regardless of the provider used, all queries use the same LINQ syntax.

Between the language’s built-in query syntax and the providers is a library of query operators added to the .NET Framework as part of LINQ capabilities. These operators perform tasks such as filtering, sorting, set theory operations, and aggregation. Since these operators are part of the .NET Framework, they can also be used without LINQ if the developer wishes.




Protect your devices with Threat Protection by NordVPN


Skip to content