News Stay informed about the latest enterprise technology news and product updates.

LINQ and XML programming in Visual Basic 9

As Visual Basic 9 nears its release, Microsoft is making a concerted effort to introduce developers to its new features. The combination of LINQ, IntelliSense and XML programming is quite possibly enough to make the release of Visual Basic 9 bigger than VB's move to the .NET Framework.

As Visual Basic 9 nears its year-end release, Microsoft is making a concerted effort to introduce developers to its new features -- notably the Language Integrated Query, or LINQ, but also improved XML support and more intuitive IntelliSense.

At Tech Ed 2007, Amanda Silver, program manager for Visual Basic, demonstrated each of these features to Visual Basic developers. Taken together, she said, they make the release of Visual Basic 9 bigger than VB's move to the .NET Framework.

More on Visual Basic and LINQ
Let's think about LINQ

Visual Basic's future: LINQ, Orcas and, yes, VB 6

How Visual Basic 9, Windows Vista appeal to the Visual Basic 6 developer

LINQ has garnered the most attention among the new features in VB 9.0 and C# 3.0, largely because it allows developers to query anything that is IEnumerable -- objects, datasets, XML and so on.

"We took the query and the transform operations and brought them into VB, and we did it in such a way that the code you write is abstracted away from the data source you are querying over," Silver said.

LINQ offers quite a bit of support for query expressions such as aggregation, partitioning, grouping and ordering. This means that, while the compiler is busy, developers should not be, Silver said: "We do all the heavy lifting. You just need to write the query you need."

These queries, moreover, can take on complex forms. If operations are built up line by line, the compiler will call them sequentially. If a query is issued on top of the results of another query, it is not executed until the results are enumerated, and only one query is issued to the database.

Structurally, LINQ queries are modeled after TSQL queries, with one important difference -- in LINQ, From comes before Select. Ever since LINQ made its debut at PDC 2005, Silver said, the message Microsoft has heard is that "IntelliSense is way more important than staying close to SQL syntax."

Given that IntelliSense now comprises much more than just keywords, such a notion is not surprising.

More on Visual Basic and XML
Using XML in Visual Basic 2005: Chapter 12 of Professional VB 2005
Mini-Guide: Data binding and XML

For example, thanks to Extension Methods, which are defined through attributes and applied to a module, a shared method can be applied as an instance method. In addition, when an object is created and properties are assigned to it, the compiler will infer the object's type, Silver said. Along those same lines, properties need not be specified, either, as the compiler will infer those based on the expression, she added.

These instances of type inference are, by default, turned on for new Visual Studio 2008 projects but turned off for migrated projects.

Developers should also notice that IntelliSense comes in handy when working with XML as well. Bring in an XML document, or copy and paste XML code into Visual Studio, and the IDE will infer its schema, saving it as an .xsd file. Once this file is passed into a VB project, full XML IntelliSense is available "anywhere that expression is valid in Visual Basic," Silver said.

This "functional construction," in which passing a set of arguments to a constructor subsequently passes a query result, is a significant improvement over the current methodology for XML programming, Silver added. This involves describing to the API what a developer is trying to do with the XML, which has to be done in a document.

Dig Deeper on .NET Framework 3.5 and Visual Studio 2008 development

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.