I presented a brief talk on LINQPad at RockNUG a couple of weeks ago. This post will elaborate on that presentation a bit, since the 30 minutes I had wasn’t nearly enough to do justice to a tool I only half-joking called the Swiss Army knife of .NET development.
In addition to enabling developers to write and execute LINQ queries, LINQPad can be used to execute SQL queries as well as compose and run code snippets in C#, VB.NET, and F#. LINQ can query a wide variety of collections and data, including SQL databases and XML. The ability to query XML with LINQ becomes quite powerful when the XML comes from WCF Data Services (an implementation of the OData protocol).
During my presentation, I queried a local version of the Northwind database, as well as the OData endpoint of Netflix. StackOverflow publishes their data via an OData endpoint as well. Additional producers of OData services can be found here, or in the Windows Azure Marketplace.
One of the nice features of LINQPad is the number of export options it provides for your query results. The results of any SQL or LINQ query written in LINQPad can be exported to Excel, Word, or HTML. The Excel and Word export capabilities give you the option of preserving the formatting LINQPad provides, or leaving it out. Once you’ve queried a database with LINQ, the results display allows you to toggle between the equivalent fluent LINQ, SQL and MSIL syntax. I demonstrated this feature by executing a SQL query against the Northwind sample database, then cutting and pasting the equivalent syntax to new query windows and running them to show that the query results were the same.
The LINQPad website pitches the tool as a replacement for SQL Server Management Studio. To test this proposition, I demonstrated LINQPad’s ability to execute stored procedures. I used the TenMostExpensiveProducts stored procedure in the Northwind database, and this script to show one way to use LINQPad to run stored procedures that take parameters.
LINQPad’s capabilities as a code snippet runner are further supported by its ability to reference custom assemblies and namespaces. So instead of dealing with all the overhead of Visual Studio just to write a console application, you could simply write them in LINQPad and reference any custom assemblies you needed.
The latest version of LINQPad also has an extensibility model, if you wanted to query databases other than SQL Server (or different querying sources).
One feature I wished I’d had time to delve into further was LINQPad’s ability to query Entity Framework models defined in Visual Studio. There’s a brief description of that capability here.
All of the query files from my presentation are available on Github.