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

  • image1452_thumb.png
    Javascript to Dart Translator

      Dart, a Google Javascript alternative was presented a few months ago and the web developer scene are a little bit unsure about the usability of Dart. To declare the language Google has translated the Javascript basics into Dart. The result is this “Translator”. In my opinion the name doesn’t find that well because it’s ...

  • image1366-570x194.png
    Twitter Bootstrap as UI-kit

      HTML and CSS are not foreign words for me but I regret, I’m not a Web designer – I see myself as a webdeveloper. But at least a dressy side is a must. But thank good there are some ready “Systems”. Twitter Bootstrap Twitter Bootstrap is a Toolkit for every kind of Web applications. ...

  • image1441.png
    Fix: the value ‚x‘ is not valid for Foo in ASP.NET MVC

      To get files into the MVC Controller Modelbinding from MVC is a clever method. But in fact it is a little bit complicated to set the error message if the connection failed. Example: public class RegisterModel { ... [Required] [DataType(DataType.EmailAddress)] [Display(Name = "Email address")] public string Email { get; set; } [Required] [Display(Name = ...

  • You Tube API – recall Video Meta files with .NET

      A loooong time ago I’ve blogged about how to access to You Tube with the Google Data APIs. After all that time there are several new ways how to recall files. Google offers You Tube a “simple” surface. If you prefer to do low-Level HTTP calls it is also possible. Aim: I want the ...

  • image1426-570x194.png
    MacBook Pro for .NET Developer – useful ore just pretty?

      I own a MacBook Pro (from 2010) for about a year now and because I’ve used to think about this Question since I have it, I’m going to blog about my experience now. My Notebook Configurations MacBook Pro April 2010 - 2,66 Intel Core i7 - 8GB RAM - 15’’ Glossy Display - Intel ...

Support us