Editor's Note

We know what you're thinking. Visual Studio 2005 has been out for a few months now. You're getting your head around it, discovering its vast inner beauty. But still, there's a nagging voice inside your head taunting you, asking why you're content to work with a released product. "You used to be cool," it says. "Remember the good times we had back in 2000, running command-line compiles on early C# code?" You smile weakly, wondering if you're hallucinating.

Part of the thrill of being a programmer is feeling like you're the first of your friends to get your hands on the newest API, the most recent build of an upcoming language, that first can of Jolt in the morning. For you, the call of LINQ is starting to become audible, faintly at first. But soon, it will reach a crescendo. You will be inexorably drawn in to take a peek at LINQ. And you probably haven't even heard of it—until now!

LINQ is the Language Integrated Query framework, which will enable the .NET Framework to provide data through a native structured query language. It will be a key feature available through C# 3.0 and Visual Basic 9.0. Visual Basic, for example, will provide support for LINQ through XML literals and late binding over XML. In effect, you'll be able to add easy data access to your code without worrying about the underlying SQL.

Here's an example. Suppose you have a database of countries that can be represented like this:

Class Country Public Property Name As String Public Property Area As Float Public Property Population As Integer End Class

If you have a collection of these objects called Countries, you can query it in code quite simply:

Dim SmallCountries = Select Country _ From Country In Countries _ Where Country.Population < 1000000

If it looks like SQL, that's because it's meant to.

With XLinq, you will be able to perform in-memory XML queries. To skip a few steps, this code will create a valid XML representation within the variable CountryInfo:

Dim CountryInfo As XElement = _ <Countries> <%= Select <Country Name=(Country.Name) Density=(Country.Population/Country.Area)> </Country> _ From Country In Countries _ </Countries>

This code would create XML that looks something like:

<Countries> <Country Name="Palau" Density="0.037117903930131008" /> <Country Name="Monaco" Density="16694.21052631579" /> <Country Name="Belize" Density="9.5512195121951216" /> </Countries>

You can even use the It identifier instead of the SQL * selector:

Dim CountriesWithCapital = _ Select It _ From Country In Countries, City In Capitals _ Where Country.Name = City.Country

This only scratches the surface of what LINQ will let you do. It's still very early. But if you want a look at the future of programming with data, you're in luck. The LINQ community preview and Visual Basic 9.0 preview are both available from the Visual Basic Future Versions page. Here you'll also find Channel 9 interviews with technical experts Paul Vick, Amanda Silver, and Erik Meijer. You can read more about the origins of LINQ here, and look at hundreds of samples on the MSDN site.

Whether to do your cutting-edge work or go bleeding edge and stay ahead of your peers is something that must be decided between you and that voice in your head. As LINQ, C# 3.0, and Visual Basic 9.0 approach their final releases, we'll have ample coverage in MSDN Magazine to help you decide. Just remember to tell your inner voice to get its own copy.


Thanks to the following Microsoft technical experts for their help with this issue: Joe Binder, Ryan Dawson, Kevin Frei, Matt Gibbs, Ken Henderson, Chris King, Ronald Laeremans, Martyn Lovell, Polita Paulus, Sebastian Poulose, Jose Reyes, Jay Roxe, Amanda Silver, Mike Stall, Kang Su Gatlin, Maura Van Der Linden, Manu Vasandani, and Jamie Wakeam.

ActiveX, Hotmail, IntelliSense, Internet Explorer, Microsoft, MSDN, MSN, Visual Basic, Visual C++, Visual Studio, Windows, Win32, WinFX, Windows Server, and Windows Vista are either registered trademarks or trademarks of Microsoft Corporation. Other trademarks or tradenames mentioned herein are the property of their respective owners. MSDN MAGAZINE DOES NOT MAKE ANY REPRESENTATION OR WARRANTY, EXPRESS OR IMPLIED WITH RESPECT TO ANY CODE OR OTHER INFORMATION HEREIN. MSDN MAGAZINE DISCLAIMS ANY LIABILITY WHATSOEVER FOR ANY USE OF SUCH CODE OR OTHER INFORMATION. MSDN and Microsoft are registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. MSDN Magazine, MSDN, and Microsoft logos are used by CMP under license from owner. MSDN Magazine is published by CMP Media LLC. CMP Media LLC is an independent company not affiliated with Microsoft Corporation. Microsoft Corporation is solely responsible for the editorial contents of this magazine.

MSDN Magazine does not make any representation or warranty, express or implied with respect to any code or other information herein. MSDN Magazine disclaims any liability whatsoever for any use of such code or other information.