Tuesday, October 19, 2010

Sending the LINQ To SQL log to the debugger output window - Kris Vandermotten

This is what the Interwebs are all about:

Sending the LINQ To SQL log to the debugger output window - Kris Vandermotten:
"The DataContext.Log property is a great help to learn writing LINQ To SQL queries. All you need to do is assign a TextWriter to it, and you get to see al the SQL statements generated by the data context. But where do you send them to? Console.Out is an option, but you probably don't want that in a release build. Furthermore, it doesn't quite work for Windows services or ASP.NET applications. That's why I wrote DebuggerWriter, an implementation of TextWriter that writes to the debugger log.

All you need to do to use it is:

MyDataContext db = new MyDataContext();

db.Log = new DebuggerWriter();"
Back in the day (pre-Internet) this sort of fix would have taken me days. I'd have to scour through books, understand the interface, code the whole thing myself, and when done I wouldn't even be able to share it. Now with the Intertubes I can just google, copy, paste, compile, and voila!

Thank you Information Scenic Byway, bawk bawk! Oh, and thanks Kris Vandermotten too...

No comments:

Post a Comment