Using the Log

LINQ to SQL sends SQL instructions each time it has to perform an operation on our demand. This is accomplished via its complex infrastructure that relies on the .NET Framework. By the way, as a developer you may be interested in understanding what really happens behind the scenes and in getting information about the real SQL instructions sent to SQL Server. Luckily you can use a SQL log that allows showing SQL instructions. You simply need to set the DataContext.Log property as follows, before taking actions you want to inspect:

northwind.Log = Console.Out

If you want to monitor everything happening, simply add the preceding code after the creation of the DataContext instance. If you apply this code before running the first example ...

Get Visual Basic® 2010 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.