There's a good selection of LINQ samples here. I ran up most of them in LINQPad.

However, some of these samples use a method called ObjectDumper (which does much the same job as object.Dump() in LINQPad).

The source for ObjectDumper can be found in this zip file. Save the files in an ObjectDumper directory somewhere and load them as a Project under Visual Studio. (Note that the sample is for VS 2008 but I had no problems doing this with VS 2005. Just remember to click on the .csproj to open the project and not the .sln!).

Then build the project which will create a .dll and add this .dll to the LINQPad "snippet" using "Advanced Properties" (F4)", then "Add" and then "Browse" to where you created the .dll.

Based on an example by Eric White, here's some simple string handling (running as always inside LINQPad).

// Per Eric White. The following is a query to split a string into words, only // allow words > 1 character, eliminate the ones that contain the letter // "y", convert the words to lower case, count the number of occurrences of // each word, and return the ten most used words.

string text = "Debugging LINQ queries can be problematic. One of the reasons is that quite often, you write a large query " + "as a single expression, and you can’t set a breakpoint mid-expression. Is LINQ really that problematic? " + "Queries can be fun as is debugging!";

Been paying around with LINQ to SQL using the excellent LINQPad and the Northwind DB.

Some samples I came up with:

(The "C# Expression" refers to the Type in LINQPad. Ensure the DB drop-down points to the Northwind DB. The lambda is generated during run time and can be viewed by clicking on the lambda symbol next to the Results tab. You can think of lambda as a function e.g. "a => a * 2" is a function that takes "a" as input and returns "a times 2".

The Dump statement just outputs the current object.)

// This works - C# Expression// Get all rows in Products - sort by ProductName

from p in Products orderby p.ProductName select p

// This is the corresponding lambda - C# Expression

Products .OrderBy (p => p.ProductName)

// C# Expression // Only show rows that have an "A" in the ProductName

from p in Products where p.ProductName.Contains("A") select p

These are all C# Statement(s) - ";" are now required at the end of declarations.