O'Reilly logo

Windows® Phone 8 Unleashed by Daniel Vaughan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

LISTING 29.9. DebugStreamWriter Class

public class DebugStreamWriter : TextWriter{    readonly int bufferSize = 256;    readonly StringBuilder stringBuilder;    public DebugStreamWriter(int bufferSize = 256) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required