ASP.NET Hosting

Sending the LINQ to SQL log to the debugger output window

When debugging LINQ to SQL code, did you wish you could easily see the SQL that gets executed? Of course there is the DataContext.Log property that is available for that. You can assign any TextWriter to this property. Console.Out is a good candidate for example, but it doesn't help much for web applications and doesn't integrate with Visual Studio nicely. Fortunately, Kris Vandermotten has a nice solution: DebuggerWriter. It's an implementation of TextWriter that writes to the debugger log.

With this solution, plug an instance of DebuggerWriter into your DataContext's Log property, and you'll be able to see the SQL queries appear in Visual Studio's Output window.

By the way, Kris also has other interesting posts about LINQ. For example, he has a series of posts about the impact the use of LINQ to SQL has over a classical Data-Access Layer (part 1, part 2).


Cross-posted from http://linqinaction.net

No Comments