Observing LINQ to SQL Queries with a Custom Log
LINQ to SQL allows you to capture the generated SQL as it is being sent to a local database. This can be achieved by creating a custom TextWriter
that outputs to the Visual Studio console window using Debug.WriteLine
. An instance of the custom TextWriter
is assigned to the Log
property of the DataContext
class.
John Gallardo demonstrates how to do this on his blog at http://bit.ly/mJYY74. The custom TextWriter
, called DebugStreamWriter
, is shown in Listing 29.9.
public class DebugStreamWriter : TextWriter{ readonly int bufferSize = 256; readonly StringBuilder stringBuilder; public DebugStreamWriter(int bufferSize = 256) ...
Get Windows® Phone 8 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.