LINQPad is a free, easy-to-use tool for developing with Language-Integrated Query (LINQ). It handles any valid Microsoft .NET Framework 3.5 C# statements against collections of any kind.
I’m a big fan of Microsoft Visual Studio, but sometimes it’s easier to fire up a lightweight tool, try some code, and use those results in my main development project. When it comes to any programming that includes LINQ, my tool of choice is LINQPad (www.linqpad.net). LINQPad is free, small (2MB), downloadable, and requires no installation.
More Than Just LINQ
The LINQPad utility was written by Joseph Albahari, who along with his brother Ben Albahari co-authored C# 3.0 in a Nutshell. Albahari includes 200 examples from this book in LINQPad. At the heart of LINQPad is a standard text editor that lets you quickly type single expressions or many statements, execute them, and get nicely formatted output to look over.
LINQPad handles any valid Microsoft .NET Framework 3.5 C# statements against collections of any kind (such as in-memory collections, XDocument-based XML, or SQL Server-based objects). The LINQPad samples don’t require that the code be based on LINQ; code can be based on any C# code snippet that you want to try out. If you want to extend the tool, you can add references to your own assemblies and build up your LINQ queries against those objects. I’ve done this often to iteratively work on queries against the business objects in my Windows Presentation Foundation (WPF) VS.NET-based solution. It’s so much quicker to use LINQPad to write the query, test it, get it right, and then paste it into my real code.
Pros: Free; no installation required; supports LINQ (e.g., objects, XML, SQL) and any other Microsoft .NET code; references external assemblies; has formatted hierarchical output; comes with lots of good documentation
Cons: No IntelliSense in the current editor (it’s planned for a future version); keyboard shortcuts are different from Visual Studio and not customizable
Rating: 4 out of 5 stars
Price: Free download
Recommendation: Definitely download and try if you’re working with LINQ or just want a fast code snippet editor.
Contact: Joseph Albahari • www.linqpad.net • Phone (Australia) 04198 23232 (International) +61 4198 23232
LINQPad displays formatted output that shows the results of your executed code. I like the hierarchical, treeview output for collections that you can expand and collapse as desired. Each node shows the object type and the count of items in a collection. In addition, you can see any embedded objects in the object graph and you can expand or collapse these objects, which gives you a visual feel for your data model.
There are three handy buttons you can use to see different types of output. The Results button is selected by default; it shows the graphical output of the query. The lambda operator shows the lambda equivalent of any of your LINQ queries that are IQueryable. The SQL button shows you any SQL statements that are executed based on the LINQ to SQL statements you executed. You can learn some complicated SQL by inspecting this output, as the following example shows:
FROM \[Orders\] AS \[t0\], \[Order Details\] AS \[t1\]
WHERE \[t0\].\[OrderID\] = \[t1\].\[OrderID\]
One of the shortcomings of LINQPad is the lack of auto completion in the editor. Many developers have come to rely on the IntelliSense offered in Visual Studio. Most of the time, I use LINQPad as a way to get the syntax right for a complicated statement or explore new possibilities with queries, and it’s very helpful to have the available members on a particular object right there in an auto completion list. The LINQPad community has been asking for IntelliSense on the support forums, and Albahari is listening—IntelliSense is in the works. A beta switch in the current version shows you that he’s working on it. Run LINQPad with a parameter of -beta and you’ll have IntelliSense:
As indicated on the support forums (forums.oreilly .com/category/22/C-3-0-in-a-Nutshell), only C# 2.0 features are currently supported.
One more feature I hope Albahari adds in a future release is the ability to customize the keyboard shortcuts available throughout the application. Shortcuts such as Ctrl+K, to comment a block of code, and U, to uncomment a block of code, while close to the Visual Studio equivalents, throw me off just enough to misuse them quite often. I’m such a keyboard-centric user that I want to map the shortcuts to those I use in Visual Studio 2008. I’d like to see keyboard commands to expand or collapse nodes in the output window added as well.