BT

Live From Redmond Coverage: LINQ Overview

| by Jonathan Allen Follow 635 Followers on Apr 25, 2007. Estimated reading time: 2 minutes |

Kit George presented the second installment of the live Orcas webcasts.

The first thing Kit George pointed out is that API designers can write their own LINQ providers that developers can use in the same way as the built-in providers. Creating a LINQ provider isn't trivial, but MS seems to be willing to offer advice.

The list of new features needed to support LINQ is impressive. Many of them are features that have been requested for years, others are most people never imagined would be introduced into VB and C#. The list given in the presentation is:

  • Query Expressions
  • XML Literals
  • XML Element Access
  • Nullable Types
  • Object Initializers
  • Local Type Inferance
  • Lambda Expressions
  • Rich Intellisense
  • Extension Methods
  • Expression Trees
  • Anonymous Types
  • Ternary Operator
  • Coalesce Operator
  • Partial Methods

Type inference was briefly covered. Type inference, already available in languages such as Haskell, has been discussed a lot recently in both .NET and Java.

Rich Intellisense refers to the much more proactive Intellisense engine. Tooltips and code completion is triggered earlier and, at times, with much more information than previous versions of Visual Studio.

Line continuation characters are required for LINQ queries in VB. And due to the length of a typical query, developers can be expected to see a lot of them.

In LINQ queries, the Select clause is optional. If included, it must appear after the From clause. This was primarily done to support Intellisense. If more than one field is included in the Select clause, an anonymous type is created with the appropriate properties. Alternately, normal objects can be created by passing in the fields to a constructor or object initializer.

The syntax for object initializers in VB is a little bulky, as it requires the use of the With keyword.

Other familiar SQL keywords such as Distinct are supported. The SQL feature "Top n" is exposed via the Take and Skip extension methods.

Unlike SQL, LINQ relies on early binding to types. This means that when binding to untyped collections the developer may have to specify the type the collection actually contains. For example, "From con As Control In Me.Controls".

Extensions methods are heavily used and can be applied to both classes and interfaces. Extensions methods for IEnumerable are included to cover common scenarios. In addition, anything you can do with the LINQ syntax can be done via these extension methods, allowing for the dynamic construction of queries.

Some features are missing from this Beta including Nullable types, Joins, Grouping, and Lambda expressions. They are expected to be included in Beta 2. LINQ providers are allowed to create their own aggregate functions for grouping.

If you want a single value from a query, say Max or Average value, the syntax changes slightly to "Dim value = Aggregate item In Collection Into Max(item)".

Queries use delayed execution. Until the data in the query is actually used, the query isn't processed. A query can even be written against another query, wherein the first query won't be executed until the results of second query is actually used, such as in a For Each loop.

LINQ to SQL supports SQL Server, but not other databases such as Oracle 10. Database vendors will have to create their own providers to enable LINQ access.

Orcas Beta 2 is expected between July and September.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss
BT