HowTo: LINQ to SQL debugging

I`m working on a project where I use LINQ to SQL. It´s very cool (and sometimes tricky ;) ), but what if I need deeper information about the "LINQ to SQL magic" – how can I debug the LINQ to SQL stuff?

1. Option: Visual Studio

The simplest option is of course Visual Studio itself. Just checking the objects – very easy.

If you want to know which SQL statement is send to the SQL Server you need another tool:

2. Option: LINQ to SQL Debug Visualizer

A powerful tool: LINQ to SQL Debug Visualizer. I can´t understand why Microsoft hide this handy tool.

3. Option: DataContext.Log

A build-in option for logging is the DataContext.Log property. It is very useful in a consol application – but not in a class library. I found a very smart "Output Logger" class on this blog: Sending the LINQ To SQL log to the debugger output window. Each generated sql statement will be send to the output window.

This are my "debugging" tools – maybe could "LinqPad" another nice tool.

Any other suggestion? Feel free to comment (you can even comment my english ;) ).

kick it on DotNetKicks.com

1 Comment so far »

  1. Polaris said

    am November 3 2008 @ 6:42 pm

    DataClasses1DataContext db = new DataClasses1DataContext();

    var organizations = from org in db.Organizations
    where org.Divisions.Count > 0
    select org;

    Debug.WriteLine(organizations);

    will output:

    SELECT [t0].[OrganizationID], [t0].[Name]
    FROM [dbo].[Organizations] AS [t0]
    WHERE ((
    SELECT COUNT(*)
    FROM [dbo].[Divisions] AS [t1]
    WHERE [t1].[OrganizationID] = [t0].[OrganizationID]
    )) > @p0

Comment RSS · TrackBack URI

Leave a comment

Name: (Required)

eMail: (Required)

Website:

Comment: