Linq to Sql Query Visualizer
Scott Guthrie described an awesome Linq to Sql Query Visualizer here. His context is Visual Studio 2008 Beta 2. Since then, it’s gotten (almost) baked into Visual Studio 2008 RTM. The functionality is the same, installing it is slightly different.
What is it:
During debugging, show the actual sql that will get executed from your linq query, and allow you to execute the query and see the results – all within a debugger visualizer.
How to get it:
Navigate to
C:\Program Files\Microsoft Visual Studio 9.0\Samples\1033
(Modify to suite if you installed Visual Studio 2008 to a different directory.)unzip CSharpSamples.zip
Navigate inside the unzipped content to
LinqSamples/QueryVisualizer
Build the project if necessary. I chose to change the solution to Release mode, since I likely won’t be debugging the visualizer. :)
Copy
SqlServerQueryVisualizer\bin\Release\LinqToSqlQueryVisualizer.dll
toC:\Users\<your name here>\Documents\Visual Studio 2008\Visualizers
(or in XP copy it toC:\Documents and Settings\<your name here>\My Documents\Visual Studio 2008\Visualizers
)Restart Visual Studio 2008
How to use it:
(graphics pillaged from Scott Gu’s original post)
Create a Linq to Sql query
Set a break point after the creation of the Linq to Sql query is formed and before the results are used – e.g. before the sql is executed.
Mouse over the results variable:
Click on the magnifying glass:
Welcome to the Linq to Sql Query Visualizer.
Note the “Original query” checkbox on the bottom-left – if you click it, you’ll see how the query is actually parameterized correctly – no sql injection here.
Note the “Execute” button on the bottom-right – if you click it, you’ll see the results that will get returned into the IEnumerable<T>
results var.
In many discussions since, I’ve heard people describe TSql constructs and syntax they’ve learned by watching the queries in this window. I can’t wait … except now that I have Linq to Sql (and Linq to Entities on the horizon), why would I want to code in TSql anymore? :)
Rob