In-Depth

Cure Data Type 'Impedance Mismatch' With LINQ

Language Integrated Query (LINQ) for .NET and its System.Query, System.Data.DLink, and System.Xml.XLink classes enable relational-to-object and XML-to-object mapping with first-class CLR data types.

General-purpose programming languages (GPPLs), such as VB, C#, and Java, suffer from a type-system disconnect with database programming languages (DBPLs), such as ANSI SQL, T-SQL and PL/SQL, and XML programming languages (XMLPLs) based on the XML Document Object Mode (XML DOM), such as XPath, XSLT, and XQuery. "Impedance mismatch" is an engineering term that's commonly applied to the incompatibility between type systems. As an example, audio engineers use transformers to convert the balanced outputs of studio-quality 600-ohm microphones to the high-impedance, unbalanced mic inputs of consumer-grade audio gear. Thus, you might equate Microsoft's new Language Integrated Query (LINQ) Project combined with VS 2005's new generic types as a "transformer" for .NET query languages.

In this article, I'll describe my initial experiences with the technical preview bits that you can download here for C# and here for VB. Both previews require a recent VS 2005 Beta 2 version and, according to the Project LINQ Readme, won't run "on builds later than this Tech Preview," which include the recently-released RC0 drop. However, today's C# and Visual Basic LINQ Tech Preview links on The LINQ Project page state that the hands-on labs and compilers support the "release candidate versions of Visual Studio 2005" and its Express editions.

I found that the preview bits install and run under VS 2005 build 8.0.50727.7; they install but some VB samples won't run under earlier build 8.0.50215.44. To verify a correct C# 3.0 compiler installation, run the XLinqIntro project from the link on the C# Readme page (see Figure 1). Be sure to run Install Visual Studio IDE Support.cmd from the Readme file's link. You must add a Console.ReadLine(); instruction after the Samples.Program class's last DumpNode(document); instruction to display Figure 1. For the VB 9.0 compiler installation, run the Visual Basic 9.0 Survey project from the link on the VB Readme page (see Figure 2). Installing the VB compiler automatically adds LINQ templates to the New Project dialog's Types list (see Figure 3). You can open the C# Readme page from \Programs\LINQ Project PDC 2005 Tech Preview and the VB Readme from \Programs\VB LINQ Preview\Readme.

Before performing any serious surgery on the sample LINQ projects or creating new ones from the New Project dialog's LINQ templates, download the LINQ documentation as Word DOCs. Start with the LINQ Project Overview, then the Visual Basic 9.0 Overview, DLink Overview, and XLink Overview. The VB examples are limited to XLink features, but the C# sample queries include a Northwind.cs class that you can add to the C# LINQ project to test the new DataContext object. According to a quote from the VBTeam's Amanda Silver in a Dr. Dobbs Journal interview, "For example, we've been working on XML integration pretty fiercely, meanwhile, we're [sic] don't have support in this initial version for DLinq." Thus, VB developers will need to wait for a later tech preview to test-drive the database integration features hyped by Microsoft's "Q&A: Microsoft to Simplify and Speed the Development of Data-Rich Applications by Extending the .NET Framework to Provide Language Integrated Query for Databases" press release. Query support for WinFS also will require DLinq.

If you've written multiple mapping files for relational-to-object mapping in .NET projects, you'll appreciate the command-line apps that future previews of the LINQ Project will provide to generate partial classes from database metadata and XML schemas. LINQ's predecessor, Microsoft Research's Cω language, has SQL2COmega.exe and XSD2COmega.exe apps to generate CLR assemblies from databases and XML Schema. Until LINQ gains similar capabilities, you'll need to write classes that implement DataContext manually. You can read more about Cω and its relationship to LINQ at the OakLeaf blog.

The LINQ Project is the new Orcas feature that's most interesting to me because it implements the former ObjectSpaces in a much more elegant way, has the potential to rival XQuery as a compositional XML query language, and promises to simplify programming of WinFS queries. Backward compatibility with VS 2005 eliminates reliance on Windows Vista and Orcas. Give this first tech preview a test drive and watch for updates on MSDN's LINQ Project site.

About the Author

Roger Jennings is an independent XML Web services and database developer and writer. His latest books include "Special Edition Using Microsoft Office Access 2007" (QUE Books, 2007) and "Expert One-on-One Visual Basic 2005 Database Programming" (WROX/Wiley, 2005). He’s also a VSM contributing editor and online columnist and manages the OakLeaf Systems blog. Jennings’ Code of Federal Regulations Web services won Microsoft’s 2002 .NET Best Horizontal Solution Award. Reach him at [email protected].

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube