Content deleted Content added
Citation bot (talk | contribs) Added date. | Use this bot. Report bugs. | Suggested by Abductive | Category:Wikipedia articles with style issues from September 2024 | #UCB_Category 270/327 |
|||
Line 25:
'''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| date = 10 June 2011}}</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 | access-date = 2009-11-21}}</ref> It also defines a set of method names (called ''standard query operators'', or ''standard sequence operators''), along with translation rules used by the compiler to translate query syntax expressions into expressions using [[Fluent interface|fluent-style]] (called method syntax by Microsoft) with these method names, [[Anonymous function#C.23 lambda expressions|lambda expressions]] and [[anonymous type]]s.
==Architecture ==
Line 73:
===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,<ref name=Skeet>{{cite book |last=Skeet|first=Jon|title= C# in Depth |date=23 March 2019 |publisher= Manning |isbn= 978-1617294532}}</ref>{{rp|75}} [[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|access-date=2012-12-19}}</ref> and [[Oxygene (programming language)|Oxygene]], with other languages like [[Nemerle]] having announced preliminary support. The language extensions include:<ref name="linq1">{{cite web | url = http://msdn.microsoft.com/en-us/library/bb397921.aspx | title = LINQ Framework | access-date = 2007-11-30}}</ref>
*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<ref name=Skeet>{{cite book |last=Skeet|first=Jon|title= C# in Depth |date=23 March 2019 |publisher= Manning |isbn= 978-1617294532}}</ref>{{rp|367}} 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.
*[[Anonymous type]]s: Anonymous types allow classes that contain only data-member declarations to be inferred by the compiler. This is useful for the Select and Join operators, whose result types may differ from the types of the original objects. The compiler uses type inference to determine the fields contained in the classes and generates [[Mutator method|accessors and mutators]] for these fields.
*[[Object initializer]]: Object initializers allow an object to be created and initialized in a single scope, as required for Select and Join operators.
Line 115:
====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 | date = 30 April 2007 | access-date = 2007-11-30}}</ref>
====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 | access-date = 2007-11-30 | archive-url = https://archive.today/20130125231336/http://www.hookedonlinq.com/LINQtoSQL5MinuteOverview.ashx | archive-date = 2013-01-25 | url-status = dead }}</ref> However, since SQL Server stores the data as [[relational database|relational data]] and LINQ works with data encapsulated in objects, the two representations must be [[Object-Relational mapping|mapped]] to one another. For this reason, LINQ to SQL also defines a mapping framework. The mapping is done by defining classes that correspond to the tables in the database, and containing all or a subset of the columns in the table as data members.<ref name="ltos">{{cite web | url = http://msdn2.microsoft.com/hi-in/library/bb425822.aspx | title = LINQ to SQL: .NET Language-Integrated Query for Relational Data | date = 30 April 2007 | access-date = 2007-11-30}}</ref> The correspondence, along with other [[relational model]] attributes such as [[primary key]]s, are specified using LINQ to SQL-defined [[attribute (computing)|attributes]]. For example,
<syntaxhighlight lang="csharp">
|