Sparky's Tool Tips: LINQPad
Brian Schroer
Posted on August 10, 2022
Of all my favorite tools, LINQPad is probably the favorite. I use it every day, several times per day.
LINQ
In 2007, Microsoft's .NET 3.5 introduced (L)anguage (In)tegrated (Q)uery, one of the killer features of .NET, and Joseph Albahari introduced LINQPad almost immediately afterward, providing the ability to do database queries using LINQ as an alternative to SQL.
Here's a screenshot from an early version of LINQPad (it still pretty much looks the same):
The screenshot above uses LINQ "query syntax", but of course, you can also use "method syntax" (.Where, .OrderBy). That's because LINQPad isn't just for LINQ and databases - It's for any any C#/F#/VB expression, statement block or program...
Code "scratchpad"
If you want to quickly try out some code, instead of creating a console app in Visual Studio, you can just open up LINQPad and and type a line or two...
I use it a lot for quick code experimentation, and have amassed a collection of tiny utility "program" queries in LINQPad (JSON and XML formatting, removing line feeds and tabs from strings, etc.), but working with databases is LINQPad's main claim to fame...
Database
As shown in the animation below that I "borrowed" from Jiří Petržilka's blog, if you query a table with foreign keys, LINQPad shows those relationships as navigation links to those entities:
Querying with LINQ is what LINQPad was created for, but you can also query with plain old SQL:
If you do query with LINQ, you can click the results "SQL" tab to see the SQL that was generated:
I almost never use SQL Server Management Studio for SQL queries any more.
Extensions, references & NuGet
You can reference .NET DLLs and NuGet packages and use them in your queries and create/save your own extension methods and classes and use them in your queries:
In this example query, the underlined code uses extensions I wrote to:
- run the SQL Server query "WITH (NOLOCK)" (in a TransactionScope with IsolationLevel.ReadUncommitted, actually) so it doesn't tie up the table
- convert from UTC time to my local time
- format a column containing JSON with indentation
Pricing
There is a free version, which I'm ashamed to admit I used for probably thousands of hours before finally doing the right thing and sending some money Joseph's way.
There are several premium license versions starting at US $59, which add autocompletion & tooltips, code formatting, cross-database querying, etc.
Summary
I'm afraid this post doesn't adequately convey LINQPad's awesomeness. I've been using it for years, and keep discovering new capabilities (interactive regular expression editing & testing !?).
I urge you to give it a try.
You can learn more about LINQPad and download the installer from
https://www.linqpad.net/.
Posted on August 10, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.