Tuesday, November 9, 2010

Introduction to LinqPad

It’s really sad that in the late 2010 most people still don’t know about this incredible little tool.  For me it is a bit like what Reflector used to be in the early days of .Net, a great and FREE productivity tool outside of the Visual Studio IDE and Microsoft tooling.


LinqPad was created by Joseph Albahari as a companion tool for his book C# 3.0 in a Nutshell.  You don’t have to buy the book to use the tool (actually I haven’t bought the book either! me bad).
It’s really difficult to do justice to LinqPad in a small blog and I don’t want to write a too long post so I’ll try to expose the most useful features to you today and eventually blog about specific ones in detail in the future.

Code Snippet execution

This is the reason I use LinqPad almost every day.  If I want to test a snippet of code I don’t create a dummy VS project, I simply try it in LinqPad.  You can even write a full program if you want and save it as a code snippet.  I use this to create most of my utility tools like when I need to read and display an xml file or generate one I just use LinqToXml.


LinqPad1

Learning Tool for Linq and other .Net features

Went I first found out about LinqPad it was when .Net 3.5 came out and understanding Linq queries was still hard for me.  The tool has a lot of good Linq code sample built in so I could learn and play with the queries.  What makes this interesting is the Dump extension method of the Object type which is really powerful to display the state of any simple or complex data structure.

LinqPad2

Integrated LinqToSql

Another useful thing to do is connecting to a database and have LinqPad setup a LinqToSql wrapper over the schema so you can query it with code rather than SQL.  I cannot say I’ve used this feature a lot but sometime it can be nice if you want to do some processing of data coming from a database.  A Linq to Entity and OData options are also available.  In the future I guess I’ll be using LinqPad to query source like NetFlix and the other OData feeds too.

LinqPad3

External Library

This is something new for me (and I guess to a lot of people given I haven’t seen much info about it on the net), you can load any dlls in LinqPad to use in your queries.  This is an excellent way to create libraries of useful functions and extension methods.  I’ll be using this feature to query assemblies using Mono.Cecil with some extra functions of my own.  I’ll share with you the result of my experiments in a future series of posts.


Go download LinqPad!  You should definitely give this great tool a try.

No comments: