Tuesday, May 6, 2008

LINQ to SQL Debugging

There are several ways to debug your Linq to sql

  • Sql Server Profiler
    But How about if you share your Sql Server with others such as staging DB ?
    It will be nightmare.
  • DataContext Command
    Console.WriteLine(ctx.GetCommand(prods).CommandText);
    But How about if you don't want to write any debug code ?
  • LINQ to SQL Debug Visualizer
    I think this is the best way to debug your LINQ to SQL.
    You can use .NET Debugging Mode

    And Click small magnifying glass in the expression above, It will launch the LINQ to SQL debug visualizer to inspect the raw SQL that the ORM will execute based on that LINQ query:

Click "Execute" button, you can even test out the SQL query and see the raw returned results that will be returned from the database:

Installing SQL debug Visualizer :

  1. Download Linq to Sql Debug Visualizer http://www.scottgu.com/blogposts/linqquery/SqlServerQueryVisualizer.zip - (From Scott Gu Blog)
  2. Copy from \SqlServerQueryVisualizer\bin\Debug\SqlServerQueryVisualizer.dll
    image
  3. Copy to C:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\Visualizers
    image

You may start debug your LINQ...

No comments: