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 ;) ).

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

About the author

Written by

Currently there is no additional info about this author.

One Response

  1. 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

    Reply

Comment on this post

Recent Posts

  • How to access an Azure Website with the local IIS Manager

      Since the end of February it is possible to access an Azure Website with the IIS Manager. Although the Azure Management site offers some information’s there are more details visible at the IIS Manager.   For the connection you will need an IIS Manager and the IIS Manager for Remote Administration Extension. It’s also […]

  • image1929-570x143_thumb.png
    Create and validate own Json-Web-Tokens (JWTs)

    If you are interested in web authentication you probably have heard about JSON Web tokens (JWT). What is a JWT? Maybe I’m not using the correct security termination but however: JWTs are used to exchange claims between two systems. For example: You want to log on to a service (like Facebook, Twitter, etc.) and want […]

  • Micro-Optimization: how to shrink or „embed“ pictures

      I’m currently working on the “CodeInside Dashboard” and since the page structure isn’t that difficult it should be possible to fulfill all of Google Pagespeed or Yahoos YSlow recommendations. One of the rules was to optimize the 4 PNGs that are embedded on the page.   Before – without optimization: Below you can see […]

  • image1979-570x194.png
    Move to Windows Azure – VMs, Word Press Migration, DNS changes

    Since mid January this blogs runs on a WordPress installation in an Azure VM. Because I always thought that the subject is quite complicated this blogpost offers a view behind the scenes. Why this move? So far this blog (both German and English Version) runs on a hoster somewhere in Germany. The main problem with this […]

  • Windows Azure Active Directory – CRUD for users and groups

      Windows Azure Active Directory? If you are not informed about the subject I recommend you to have a look on this Azure Info site. Which resources are there? The Azure AD contains the following entities: - Users - Groups - Contacts - Roles Access to the directory or on the “directory graph” Although the […]

Support us