A few days ago I was reading through my Twitter feed on my phone when I read a post about a tool called LINQPad. This was the first time I’d heard of it so I hopped over to the LINQPad web site to see what it was all about. After a few minutes of browsing I made a mental note to download and try it when I got back to my laptop. I’m glad I did.
I’ve been using LINQPad for a little less than a week now and it quickly found a place in my toolkit right next to Visual Studio. In fact, if I have VS open chances are good that LINQPad is also open. What could a tool named “LINQPad” do to get such good placement in my toolkit? Isn’t it just for playing with and learning LINQ? In short, no. LINQPad is much more than its name implies.
Capabilities
LINQPad does offer great support for LINQ. Full support for LINQ to Objects, LINQ to XML, and LINQ to SQL is available out of the box. One of the most powerful features is LINQPad’s ability to connect to a SQL Server database and automatically build classes to represent the tables and columns allowing the database to be queried using LINQ to SQL rather than traditional SQL. No setup beyond entering the connection information is necessary. Entity Framework and WCF Data Services are also supported. But that’s just LINQ! Didn’t I say it’s more than its name implies?
I find that the real power of LINQPad comes from its ability to execute any C# or VB expression, statement, or program. This capability has some implications for ad-hoc testing and prototyping. Instead of littering your development folder(s) with simple single-use console applications just use LINQPad to prove-out a piece of code then copy/paste the code into your project. You can even add references to existing assemblies to expose the functionality to your ad-hoc code.
I mentioned that LINQPad supports execution of any C# or VB expression, statement, or program but what exactly does that mean? Depending on the selected language option LINQPad will behave a bit differently.
Expression
The expression option allows a single C#/VB expression. This is useful for testing regular expressions, playing with string formatting options, or anything else that can be expressed with a single line of code.
Statement(s)
More often than not our ad-hoc code will need more than one line. This is where the statement(s) option comes in. I’ve found this useful for prototyping and solidifying the body of a method and for executing database queries.
Program
The Program option is the most robust of the three. It allows an entire program complete with a Main() method and classes to be written within LINQPad. The possibilities here are endless.
Using LINQPad for ad-hoc testing should supplement rather than replace formal unit testing. Formal unit testing included with the project’s build process is still very important for on-going development.
Availability
LINQPad is not an open source project but it is offered free of charge. An auto-completion add-on is available for a small fee. The software can be downloaded as either a stand-alone executable or a low-impact installer from the LINQPad web site. All that’s really needed is .NET 3.5.
Given the power for the price I highly recommend grabbing a copy and at least trying it out. Consider giving the LINQPad Challenge a try. What do you have to lose?