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 Code Inside Team

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

  • image1825-439x194_thumb.png
    Change the WebDeploy Port or why do I need port 8172?

      If you use WebDeploy on a server operation system you would usually use Port 8172. But what is this Port for and can I change it? Hint: For installing the WebDeploy I recommend this Blogpost. Port 8172 = IIS Management Service Default Port The Port 8172 is the default port of the IIS Management ...

  • Windows Phone Fonts & what if Visual Studio lies

    Today I was confronted with a little Problem: my Windows Phone App refused to show me the Font I choose – also other thinks didn’t work. Although the Visual Studio Designer did show the Fonts: Unfortunately there isn’t much left in the Emulator: Reason for this: Windows Phone doesn’t include all the typos Windows does ...

  • Json-Online-Tools: Viewer & Json2Csharp generator

      Wherever APIs are mentioned the JSON format I not far away. Since I’m using two tools regularly I would like to introduce you to them. JSON Viewer If you only see the JSON-Text you are usually not able to see the structure. With the help of JSON Viewer you can have an easy overview: ...

  • Windows Phone SDK & „System“-Icons

      Although the Metro Design focuses a lot on Typography Icons are still quite important. If you install Windows Phone SDK you will receive 36 Icons. You can find them here: C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v8.0\Icons Unfortunately many Icons you might know from the common applications are not integrated. Pedro Lamas extracted 99 additional Icons ...

  • image1830-570x194.png
    How can I figure out if my ADFS 2.0 works?

      I was working with ADFS 2.0 (“Active Directory Federation Services”) for a while when this simple question crossed my mind: How can I figure out if the connection between ADFS and AD “works”? Here is a simple test… What is ADFS? If you need some “position of trusts” beneath the AD-boarders you choose an ...

Support us