ArticleslgStudy

science

Language Integrated Query

Language Integrated Query is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Language Integrated Query rather than just read about it. In short: Language Integrated Query (LINQ, pronounced "link") is a Microsoft .NET framework component that adds native data querying abilities to .NET languages, originally released as a major part of .NET Framework 3.5 and C# 3.0 in 2007. LINQ extends the language by the addition of query expressions, which are akin to SQL statements, and can be used to conveniently extract and process data from arrays, enumerable classes, X…

Key takeaways

  • Language Integrated Query belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Language Integrated Query to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Language Integrated Query from memory before moving on to harder problems.

Reference excerpt

Language Integrated Query (LINQ, pronounced "link") is a Microsoft .NET framework component that adds native data querying abilities to .NET languages, originally released as a major part of .NET Framework 3.5 and C# 3.0 in 2007. LINQ extends the language by the addition of query expressions, which are akin to SQL statements, and can be used to conveniently extract and process data from arrays, enumerable classes, XML documents, relational databases, 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 or monadic parsers. 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-style (called method syntax by Microsoft) with these method names, lambda expressions and anonymous types.

Architecture

Standard query operator API 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 operators defined by LINQ is exposed to the user as the Standard Query Operator (SQO) application programming interface (API). The query operators supported by the API are:

Select The Select operator performs a projection on the collection to select interesting aspects of the elements. The user supplies an arbitrary function, in the form of a named or lambda expression, which projects the data members. The function is passed to the operator as a delegate. This implements the Map higher-order function.

Where The Where operator allows the definition of a set of predicate rules that are evaluated for each object in the collection, while objects that do not match the rule are filtered away. The predicate is supplied to the operator as a delegate. This implements the Filter higher-order function.

SelectMany For a user-provided mapping from collection elements to collections, semantically two steps are performed. First, every element is mapped to its corresponding collection. Second, the result of the first step is flattened by one level. Select and Where are both implementable in terms of SelectMany, as long as singleton and empty collections are available. The translation rules mentioned above still make it mandatory for a LINQ provider to provide the other two operators. This implements the Bind higher-order function.

Sum, Min, Max, Average These operators optionally take a function that retrieves a certain numeric value from each element in the collection and uses it to find the sum, minimum, maximum or average values of all the elements in the collection, respectively. Overloaded versions take no function and act as if the identity is given as the lambda.

Aggregate A generalized Sum/Min/Max. This operator takes a function that specifies how two values are combined to form an intermediate or the final result. Optionally, a starting value can be supplied, enabling the result type of the aggregation to be arbitrary. Furthermore, a finalization function, taking the aggregation result to yet another value, can be supplied. This implements the Fold higher-order function.

Join, GroupJoin The Join operator performs an inner join on two collections, based on matching keys for objects in each collection. It takes two functions as delegates, one for each collection, that it executes on each object in the collection to extract the key from the object. It also takes another delegate in which the user specifies which data elements, from the two matched elements, should be used to create the resultant object. The GroupJoin operator performs a group join. Like the Select operator, the results of a join are instantiations of a different class, with all the data members of both the types of the source objects, or a subset of them.

Take, TakeWhile The Take operator selects the first n objects from a collection, while the TakeWhile operator, which takes a predicate, selects those objects that match the predicate (stopping at the first object that doesn't match it).

Skip, SkipWhile The Skip and SkipWhile operators are complements of Take and TakeWhile - they skip the first n objects from a collection, or those objects that match a predicate (for the case of SkipWhile).

OfType The OfType operator is used to select the elements of a certain type.

Concat The Concat operator concatenates two collections.

OrderBy, ThenBy The OrderBy operator is used to specify the primary sort ordering of the elements in a collection according to some key. The default ordering is in ascending order, to reverse the order, the OrderByDescending operator is to be used. ThenBy and ThenByDescending specifies subsequent ordering of the elements. The function to extract the key value from the object is specified by the user as a delegate.

Reverse The Reverse operator reverses a collection.

GroupBy The GroupBy operator takes a function that extracts a key value and returns a collection of System.Linq.IGrouping<K, V> objects, for each distinct key value. The System.Linq.IGrouping<K, V> objects can then be used to enumerate all the objects for a particular key value.

Distinct The Distinct operator removes duplicate instances of an object from a collection. An overload of the operator takes an equality comparator object which defines the criteria for distinctness.

Union, Intersect, Except These operators are used to perform a union, intersection and difference operation on two sequences, respectively. Each has an overload which takes an equality comparator object which defines the criteria for element equality.

SequenceEqual The SequenceEqual operator determines whether all elements in two collections are equal and in the same order.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Language Integrated Query

Start with the simplest possible case. Write down what Language Integrated Query claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Language Integrated Query before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Language Integrated Query ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Language Integrated Query

In research
Language Integrated Query appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Language Integrated Query in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Language Integrated Query is common in secondary-school and first-year university syllabi. It links to neighbouring topics .NET terminology, Query languages, XML data access, so understanding it makes those chapters shorter.
In everyday life
Look for Language Integrated Query outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Language Integrated Query” →

How to study Language Integrated Query in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Language Integrated Query means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Language Integrated Query out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Language Integrated Query in simple terms?

Language Integrated Query (LINQ, pronounced "link") is a Microsoft .NET framework component that adds native data querying abilities to .NET languages, originally released as a major part of .NET Framework 3.5 and C# 3.0 in 2007. LINQ extends the language by the addition of query expressions, which…

Why does Language Integrated Query matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Language Integrated Query?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Language Integrated Query.

Tags

  • .NET terminology
  • Query languages
  • XML data access

Keep exploring