InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

Master LINQ with LINQPad

Posted by Al Tenhundfeld on Feb 04, 2009

Sections
Development
Topics
.NET Framework ,
.NET
Tags
LINQ

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.

Good stuff by Dan Tines Posted
  1. Back to top

    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.

Educational Content

New-age Transactional Systems - Not Your Grandpa's OLTP

John Hugg discusses high volume transaction processing applications with high and low frequency profiles, and how VoltDB can be used for that purpose.

Cool Code

Kevlin Henney examines code samples to see what can be learned from them starting from the premise that one won’t write great code unless he knows how to read it.

Collaboration: At the Extremities of Extreme

Jason Ayers share the observations he made watching a team of developers collaborating in real time on the same code base, pushing XP, pair programming and continuous integration to their extremes.

Yesod Web Framework

Michael Snoyman presents Yesod, a web framework written in Haskell and containing a web server, templating, ORM, libraries (templating, gravatar, etc.).

Transactions without Transactions

Richard Kreuter and Kyle Banker on how to avoid classical RDBMS transactional systems by using compensation mechanisms, transactional messaging or transactional procedures.

Attila Szegedi on JVM and GC Performance Tuning at Twitter

Attila Szegedi talks about performance tuning Java and Scala programs at Twitter: how to approach GC problems, the importance of asynchronous I/O, when to use MySQL/Cassandra/Redis, and much more.

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.