I use LINQPad almost every day to execute any C# code I write, and sometimes it totally replaces Visual Studio for me. Moreover, I do not need to use SQL Server Management Studio for simple queries anymore. Unlike VS and SSMS, LINQPad is light and fast. If you want to see how valuable tool it is, just read this article till the end.
Simple queries (Expression)
LINQPad can run any C#, VB and F# code. Both LINQ queries and source code should be written using the syntax of the selected language. The tool automatically colours the source code according to standard.
The outcome of each query is presented in the results view – either in a text format (there is an HTML underneath) or in a grid. Additionally, you can see IL statements and execution tree for each query.
Complex queries (Statements)
LINQPad can also run a series of queries. This feature comes in handy when you want to execute more complex query. It is worth mentioning that LINQPad fully supports automatic code completion (IntelliSense).
Console application (Program)
In LINQPad you can easily write small console application. Integrated debugger gives you the possibility to track each line of the code, step by step. You can also see values for each variable of your code. You can refer to any .NET Framework assembly.
External assemblies and NuGet
LINQPad allows you to refer external assemblies and use their functionalities in the queries. This power feature gives you a broad perspective on the use of this tool. If it is not enough for you, then the real killer feature is the possibility of using NuGet packages.
Executing database queries is the main functionality that I use on a daily basis. LINQPad is a tremendous tool for that. It can present results in a grid and later on you can easily edit them. You can also navigate between data relation using special links. Just a simple click and the application will get additional data and present it to you. After executing your query in SQL tab view, you can see the LINQ query translated to pure SQL.
LINQPad supports all kinds of SQL queries. Not only does it allow you to get and modify data, but also transform the database schema. If necessary, you can also execute and edit stored procedures, functions.
The examples below illustrate the aforementioned ability to use logic from external assemblies in queries.
In the first example, right after retrieving data from the database, but before displaying it, I can decrypt (or not) specific data depending on the particular field.
In another example, I convert an int from a database to an enum from the system, so the displayed results are less enigmatic (the specific enum value is more readable than the number).
Built-in class Util
LINQPad has a built-in static class named Util. This class contains dozens of helpful methods complete with documentation, so IntelliSense displays hints for each of them. Here are a few of them:
- Break() – break in debug executing of query
- ClearResults() – clear results view
- Cmd() – run an external application
- DisplayWebPage() – display web page in results view
- Dump() – display object/value in results view
- GetPassword() – get previously stored password from password manager
- Image() – load and display image in results view
- ReadLine() – get input form user
- Run() – run next script
Command line application (LPRun.exe)
The LINQPad application has equipped an executable LPRun.exe file, which is used to run/execute scripts written in LINQPad (*.linq) from the command line. It gives you the ability to automate certain operations/processes.
LINQPad is a small application with great capabilities. The ability to run any source code from the three available languages and the functionality of database communication makes this tool extremely useful in everyday work. Referring to external assemblies and possibility to use NuGet packages makes LINQPad even more functional.