BT

Master LINQ with LINQPad

| by Al Tenhundfeld Follow 0 Followers on Feb 04, 2009. Estimated reading time: 1 minute |

LINQPad is a free standalone application written by Joseph Albahari as an add-on for his C# 3.0 in a Nutshell.

LINQPad is fundamentally a LINQ interpreter with an IDE and SQL integration built around it. LINQPad has a simple but powerful user interface allowing immediate execution of LINQ expressions, including multi-statement snippets of LINQ to SQL, LINQ to Objects, and LINQ to XML.

LINQPad UI

LINQPad offers several execution modes:

  • C# (or VB) Expression
  • A single C# or VB.NET LINQ expression is executed, and the resulting object is displayed in the results window.
  • C# (or VB) Statement(s)
  • An arbitrary number of LINQ expressions can be executed. LINQPad has a Dump extension method defined to send objects and text to the results window during execution.
  • C# (or VB) Program
  • Execution context is placed within a Main() method, allowing definition of other classes and methods inside LINQPad editor to support testing.
  • SQL
  • Provides ad-hoc querying of data using SQL.

It's important to remember that LINQPad will execute any C# (or VB.NET) code statements, not just LINQ expressions. This means LINQPad is useful for any code snippet needing simple testing, e.g., tricky numeric format strings or Regex matching.

 

LINQPad comes with numerous sample LINQ expressions that show the nuances and power of LINQ, covering beginner examples along with more advanced concepts like deferred execution and projection. LINQPad also has a helpful learning feature that presents various options for viewing results:

  • Default results view
  • A simple graphical representation of the objects and text returned from statements
  • Lambda view
  • LINQ expressions translated into lambda expressions, if applicable
  • SQL view
  • LINQ expressions translated into SQL, if applicable
  • IL view
  • Microsoft Intermediate Language generated for code statements

 

LINQPad provides extensibility by allowing users to reference custom assemblies and import custom namespaces. LINQ to Entities can be supported through this extensibility.

Beyond a learning and testing tool, LINQPad is growing in popularity as a utility to perform ad-hoc queries against a SQL database.

Simple LINQ to SQL expression output to results view: 

LINQPad LINQ to SQL

Simple LINQ to SQL expression output to lambda view: 

LINQ to SQL - lambda view

Simple LINQ to SQL expression output to SQL view: 

LINQ to SQL - SQL view

LINQPad is free and self updating. Intellisense is now available but only included in the $19 licensed version. LINQPad does not require Visual Studio but does require .NET Framework 3.5.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Good stuff by Dan Tines

I just happened to download it yesterday, but unfortunately it only works with SQLServer and Oracle (I believe). It would be nice if third party, compatible providers (DevArt) could be plugged in.

On a somewhat related note, it would be great if Mono's C# REPL was ported to ported to Visual Studio.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss
BT