Content deleted Content added
m Task 18 (cosmetic): eval 19 templates: del empty params (5×); del |url-status= (1×); |
m Task 18 (cosmetic): eval 19 templates: hyphenate params (18×); |
||
Line 22:
'''Language Integrated Query''' ('''LINQ''', pronounced "link") is a [[Microsoft]] [[.NET Framework]] component that adds native data [[Query language|querying]] capabilities to [[List of CLI languages|.NET languages]], originally released as a major part of [[.NET Framework 3.5]] in 2007.
LINQ extends the language by the addition of query [[Expression (computer science)|expressions]], which are akin to [[SQL]] statements, and can be used to conveniently extract and process data from [[Array data structure|arrays]], enumerable [[class (computer science)|class]]es, [[XML]] documents, [[relational database]]s, and third-party data sources. Other uses, which utilize query expressions as a general framework for readably composing arbitrary computations, include the construction of event handlers<ref name="reactive">{{cite web | url = http://msdn.microsoft.com/en-us/devlabs/ee794896.aspx | title = Rx framework}}</ref> or [[Monad (functional programming)|monadic]] [[Parsing|parsers]].<ref name="parscomb">{{cite web | url = http://blogs.msdn.com/lukeh/archive/2007/08/19/monadic-parser-combinators-using-c-3-0.aspx | title = Monadic Parser Combinators using C#3 |
Ports of LINQ exist for [[PHP]] ([https://phplinq.codeplex.com/ PHPLinq]), [[JavaScript]] ([https://github.com/mihaifm/linq linq.js]), [[TypeScript]] ([https://github.com/kutyel/linq.ts linq.ts]), and [[ActionScript]] ([http://actionlinq.riaforge.org/ ActionLinq]), although none are strictly equivalent to LINQ in the .NET inspired languages C#, F# and VB.NET (where it is a part of the language, not an external library, and where it often addresses a wider range of needs).{{citation needed|date=October 2018}}
Line 31:
In what follows, the descriptions of the operators are based on the application of working with collections. Many of the operators take other functions as arguments. These functions may be supplied in the form of a named method or anonymous function.
The set of query [[Operator (programming)|operator]]s defined by LINQ is exposed to the user as the Standard Query Operator (SQO) [[API]]. The query operators supported by the API are:<ref name="sqo">{{cite web | url = http://download.microsoft.com/download/5/8/6/5868081c-68aa-40de-9a45-a3803d8134b8/standard_query_operators.doc | title = Standard Query Operators | publisher = Microsoft |
;Select:
{{Further|Map (higher-order function)}}
Line 68:
The Standard Query Operator API also specifies certain operators that convert a collection into another type:<ref name="sqo"/>
* AsEnumerable: Statically types the collection as an <code>IEnumerable<T></code>.<ref name="Enumerable Class">{{cite web|title=Enumerable Class|url=http://msdn.microsoft.com/en-us/library/system.linq.enumerable(v=vs.110).aspx|work=msdn|publisher=Microsoft|
* AsQueryable: Statically types the collection as an <code>IQueryable<T></code>.
* ToArray: Creates an array <code>T[]</code> from the collection.
Line 78:
===Language extensions===
While LINQ is primarily implemented as a [[library (computing)|library]] for .NET Framework 3.5, it also defines optional language extensions that make queries a first-class [[language construct]] and provide [[syntactic sugar]] for writing queries. These language extensions have initially been implemented in [[C Sharp (programming language)|C#]] 3.0, [[VB.NET|VB 9.0]], [[F Sharp (programming language)|F#]]<ref name="linq">{{cite web|title=Query Expressions (F#)|url=https://docs.microsoft.com/en-gb/dotnet/fsharp/language-reference/query-expressions|website=Microsoft Docs|
*Query syntax: A language is free to choose a query syntax that it will recognize natively. These language keywords must be translated by the compiler to appropriate LINQ method calls.
*Implicitly typed variables: This enhancement allows variables to be declared without specifying their types. The languages C# 3.0 and Oxygene declare them with the <code>var</code> keyword. In VB9.0, the <code>Dim</code> keyword without type declaration accomplishes the same. Such objects are still [[strong typing|strongly typed]]; for these objects the compiler infers the types of variables via [[type inference]], which allows the results of the queries to be specified and defined without declaring the type of the intermediate variables.
Line 117:
====LINQ to Objects====
The LINQ to Objects provider is used for in-memory collections, using the local query execution engine of LINQ. The code generated by this provider refers to the implementation of the standard query operators as defined on the <code>Sequence</code> pattern and allows <code>IEnumerable<T></code> collections to be queried locally. Current implementation of LINQ to Objects perform interface implementation checks to allow for fast membership tests, counts, and indexed lookup operations when they are supported by the runtime type of the IEnumerable.<ref name="Enumerable.ElementAt">{{cite web | url = http://msdn.microsoft.com/en-us/library/bb299233.aspx | title = Enumerable.ElementAt |
====LINQ to XML (formerly called XLINQ)====
The LINQ to XML provider converts an XML document to a collection of <code>XElement</code> objects, which are then queried against using the local execution engine that is provided as a part of the implementation of the standard query operator.<ref>{{cite web | url = http://msdn2.microsoft.com/hi-in/library/bb308960(en-us).aspx | title = .NET Language-Integrated Query for XML Data |
====LINQ to SQL (formerly called DLINQ)====
The LINQ to SQL provider allows LINQ to be used to query [[Microsoft SQL Server]] databases, including [[SQL Server Compact]] databases. Since SQL Server data may reside on a remote server, and because SQL Server has its own query engine, LINQ to SQL does not use the query engine of LINQ. Instead, it converts a LINQ query to a [[SQL]] query that is then sent to SQL Server for processing.<ref>{{cite web | url = http://www.hookedonlinq.com/LINQtoSQL5MinuteOverview.ashx | title = LINQ to SQL |
<syntaxhighlight lang="csharp">
Line 142:
====LINQ to DataSets====
Since the LINQ to SQL provider (above) works only with [[Microsoft SQL Server]] databases, in order to support any generic database, LINQ also includes the LINQ to DataSets. It uses ADO.NET to handle the communication with the database. Once the data is in ADO.NET Datasets, LINQ to DataSets execute queries against these datasets.<ref>{{cite web | url = http://www.hookedonlinq.com/LINQtoDatasets.ashx | title = LINQ to DataSets |
==Performance==
Line 150:
| date=2007-12-21
|last=Vider|first=Guy
|
| url=http://msdn.microsoft.com/en-us/magazine/cc721610.aspx
| title=Increase LINQ Query Performance
Line 157:
| quote=''While it is true that LINQ is powerful and very efficient, large sets of data can still cause unexpected performance problems''
| date=2008
|
'''LINQ to XML''' and '''LINQ to SQL''' performance compared to ADO.NET depends on the use case.<ref>{{cite web
Line 166:
| quote=''When calling a query multiple times with Entity Framework the recommended approach is to use compiled LINQ queries. Compiling a query results in a performance hit the first time you use the query but subsequent calls execute much faster''
| date=2010-08-06
|
| url=http://www.codeproject.com/KB/dotnet/LinQ_Performance_net3_5.aspx
| title=Performance comparisons LinQ to SQL, ADO, C#
| date=2008-05-25
| last=Kshitij|first=Pandey
|
==PLINQ==
Version 4 of the .NET framework includes [[Parallel Extensions|PLINQ]], or ''Parallel LINQ'', a [[parallel computing|parallel]] execution engine for LINQ queries. It defines the <code>ParallelQuery<T></code> class. Any implementation of the <code>IEnumerable<T></code> interface can take advantage of the PLINQ engine by calling the <code>AsParallel<T>(this IEnumerable<T>)</code> extension method defined by the ParallelEnumerable class in the System.Linq namespace of the .NET framework.<ref name="ParallelEnumerable">{{cite web | url = http://msdn.microsoft.com/en-us/library/dd413602(v=vs.110).aspx | title = ParallelEnumerable Class |
==See also==
|