04 September 2007

Cool LINQ Utility

Like a lot of you out there, I've been spending a bit of time learning the new Language Integrated Query (LINQ) features available in the .NET Framework 3.5 (still in beta).  LINQ provides some very powerful capabilities for querying not only databases but other data types as well (e.g. XML, .NET collections, arrays, etc.).  Although the syntax is similar to SQL, it is not exactly the same which offers a bit of a learning curve.

I came across a utility called LINQPad a few days ago that has been helping me get over the learning curve with LINQ.  This utility offers functionality similar to the query functionality in SQL Enterprise Manager.  You create ad-hoc queries using the LINQ syntax and view the results in a hierarchical format (where applicable).

There is an interesting challenge on the LINQPad site that goes as follows:

  • Locate the shortcut for SQL Management Studio on your Start Menu and move it some place else.
  • In its place, insert a shortcut to LINQPad.
  • For the next week, perform all your ad-hoc SQL queries using only LINQPad.

I'm currently about 2 days into the challenge and I have to say that it's a completely different mindset.  I also have to admit that I've cheated at least once and used SQL Enterprise Manager to run some queries because I was under a time crunch and didn't have the time to figure out exactly how I could use LINQ to achieve a particular problem.  However, I suspect that after another week or so I should have a very good understanding about the LINQ syntax (at least for database queries).

You can download and read more about LINQPad here.  Also, here are a couple of good LINQ reference sites for anyone starting out with LINQ: