InfoQ

News

LINQ Tooling

Posted by Hartmut Wilms on Apr 17, 2008 08:21 AM

Community
.NET
Topics
.NET Framework
Tags
LINQ

Besides the ubiquitous praise within the community, LINQ has quite a steep learning curve.  Two tools, VLinq and LINQpad, try to help developers become more familiar with the LINQ syntax.

The Visual LINQ Query Builder (VLinq) is an academic project developed by Microsoft France interns in collaboration with Microsoft Corporation. Mitsuru Furuta, Microsoft France's manager and project lead, describes the project goal in his announcement:

The VLinq project as any designer helps you to build graphically Linq to Sql queries but we wanted to keep it visually very close from the code. The goal is not to hide the generated code but to make it visible in the designer. It's a kind of mix between a classical designer and a graphical intellisense.

VLinq is an add-in for Visual Studio 2008, which provides a designer that allows to visually build LINQ queries with a user experience similar to the Microsoft Access Query Builder. The project, including binaries and source code, is available for download on MSDN Code Gallery.

VLinq adds a new item template to Visual Studio, which creates a designer within the selected project (.vlinq extension). In the VLinq bag designer you can create a new query or edit existing ones. The query designer allows to drag entity classes (created by the LINQ to SQL designer) from the Class Browser onto the design surface. You can now build queries on these entities. The VLinq designer provides full "graphical intellisense" on the entities' properties.

When building the solution VLinq generates a static class, which provides methods that accept a DataContext as a parameter, perform the visually designed queries, and return an IQueryable object on the corresponding, strongly-typed entity. In your application code you simply instantiate a new DataContext (created by LINQ to SQL) and invoke those "query" methods. Thus the static "query" class serves as a container for your project's LINQ queries. Have a look at the details in the How-To video or the Quick Reference.

In addition VLinq provides a preview mode that allows to issue queries built within the designer against a database at design time, which helps testing your queries. In order to issues queries in the preview mode you have to set the connection string of the database in the VLinq designer properties. The preview provides three views: query results, LINQ to SQL SQL statements, and the generated code by VLinq.

 

LINQPad takes a very different approach. It is a free tool that was developped by Joseph Albahari as an add-on to the C# 3.0 in a Nutshell book.

LINQPad is a stand-alone application that does not require Visual Studio, needs no installation, is self-updating, and can be used in several ways:

  • Substitute for the SQL Management Studio query editor (or similar query tools): "interactively query SQL databases in a modern query language: LINQ"
  • LINQ interpreter: experiment with LINQ queries  and the new C# 3.0 language feature; "experience the coolness of LINQ and functional programming"
  • Code Snippet IDE: create and manage code snippets, which might be executed instantly within LINQPad

According to the LINQPad homepage LINQPad

... supports everything in C# 3.0 and Framework 3.5:

  • LINQ to SQL
  • LINQ to Objects
  • LINQ to XML

LINQPad is also a great way to learn LINQ: it comes preloaded with 200 examples from [the C# 3.0 in a Nutshell book].

The examples include documentation of the tool and the various ways of using LINQ. LINQPad allows to create new databases and to store database connections, which are displayed in a tree view on the left. The samples contain code to create demo tables in these databases. Every query stores the connection data, which assures that every time the query is reopened the connection data reappears in the connection tree.

LINQPad stores the queries in a folder structure within the user's home directory. Code snippets (queries) can thus be grouped arbitrarily.

Every query can be executed instantly, edited, extended and executed again. Queries are not restricted to single statements. They can consist of an arbitrary amount of statements. In order to support viewing results at every step of the source, LINQPad provides an extension method called Dump(), which dumps the query results in the output view. Dump returns the object, on which it was invoked, which allows to use Dump() within message chaining - dumping results at every stage of a LINQ query.

The output view can be switched between results, method-based query, and generated SQL statements. The "lambda"  button switches to a view that shows how the linq query expression is resolved to a method-based query. The "SQL" button shows the generated SQL statements, when using LINQ to SQL.

LINQPad is also extensible. In the advanced properties, additional assemblies and additional namespaces can be added and imported. This allows to use your own classes and extension methods within LINQPad!

LINQPad does not support intellisense in the current release, but it is a top priority for future releases.

 

Both tools are valuable assets, when getting to know LINQ. VLinq supports developers using Visual Studio and LINQ to SQL, who are accustomed to visual designers. LINQPad is a great help for anybody who wants to explore every secret of LINQ without being required to press F5 to build and run a sample application.

LINQ Tooling by Arnold Sia Posted Apr 17, 2008 8:41 PM
  1. Back to top

    LINQ Tooling

    Apr 17, 2008 8:41 PM by Arnold Sia

    Nice article ... I am looking forward in testing these two tools.

Educational Content

Bindings, Platforms, and Innovation

This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.

Orchestrating Long Running Activities with JBoss / JBPM

This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.

Neo4j - The Benefits of Graph Databases

This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.

Realistic about Risk: Software development with Real Options

This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.

Communication Flexibility Using Bindings

This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.

Writing DSLs in Groovy

After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.

Scaling Agile with C/ALM (Collaborative Application Lifecycle Management)

IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.

Concurrent Programming with Microsoft F#

Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.