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 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.
York Xyander, Bodo Junglas Jul 31, 2015