Monday, March 05, 2007

Updated Orcas March 2007 CTP LINQ C# Samples

Charlie Calvert has posted updated replacements for all downloadable C# LINQ samples for the Orcas March 2007 CTP. You can find links to the original C# and VB LINQ samples by searching online help for LINQ samples. Here's a list of the current sample set (not the same as online help's list):
  • Sample Queries -- Provides examples of query operations for LINQ to Objects, LINQ to SQL, LINQ to XML and LINQ to Datasets. (These are the "101 LINQ Queries" samples.)
  • Object Dumper Sample -- Includes a library that you can add to your solution to output the results of LINQ queries for testing purposes.
  • Windows Forms Data Binding Sample -- Demonstrates how to use LINQ in Windows Forms databinding scenarios.
  • Reflector Sample -- Generates an HTML document that outlines the public API for a given assembly.
  • Expression Tree Visualizer Sample -- Provides a working implementation of a visualizer that can be run inside the Visual Studio debugger to view the contents of an expression tree.
  • Data Folder -- Provides special version of the Northwind database and XML files used by other LINQ samples.
  • LINQ to Northwind Sample -- Provides examples of using LINQ to SQL to query a database.
  • XLinqIntro Sample -- Introduces basic LINQ to XML features in a console application.
  • PasteXmlAsXlinq Add-In Sample -- An AddIn class to paste XML on the clipboard as C# LINQ to XML code.
  • RSS Sample -- This sample acts as a tiny web server that aggregates several RSS feeds. An Internet connection is required.
  • Simple Lambda Expressions Sample -- Provides examples of simple lambda expressions.
  • Dynamic Query Sample -- Illustrates how to create LINQ queries dynamically at runtime.

Charlie also produced a seven-minute "overview" video that demonstrates how to run several of the samples.

Running Samples from a Remote SQL Server Instance

If you don't install a local instance of SQL Server (to make the Project Designer's Properties window operable), you must change the connection strings for LINQ to SQL samples. For example, the Sample Queries project's LinqToSqlSamples class requires commenting all existing connection string code and writing a new connection string for the remote instance (OAKLEAF-VS20 for this example):

public class LinqToSqlSamples : SampleHarness { //private readonly static string dbPath = ...; //private readonly static string sqlServerInstance = ...; //private readonly static string connString = ...; //private readonly static string connString = ...;

private readonly static string connString = @"Server=OAKLEAF-VS20\SQLEXPRESS; Database=Northwind;Integrated Security=SSPI";

The remote instance must have the Northwind sample database installed by executing the Instnwnd.sql script or attaching the Northwind.mdf file after you run the SQL2000SampleDb.msi installer.