I'm using Linq to SQL. I have a DataContext against which I am .SubmitChanges()'ing. There is an error inserting the identity field, and I'd like to see the query it's using to insert this identity field.
I don't see the query itself within the quickwatch; where can I find it from within the debugger?
Further to Portman's answer, if you're a console application it's as simple as:
Or you could use something like Linq2SQL Profiler which is a rather excellent tool and in fact the right tool for the job:
I agree that Linq to SQL Profiler is the right tool for this job. But if you don't want to spend the money or just need to do something simple, I like the DebugTextWriter approach.
After reading this question I went off looking for something more robust. It turns out Damien Guard also wrote a very nice article about building different writers to deal with different things like outputting to Memory, Debug, a File, Multiple Destinations, or even using simple Delegates.
I wound up using a couple of his ideas and writing an ActionTextWriter that can handle more than one delegate, and I thought I would share it here:
You can add as many actions as you like. This example writes to a log file and the Console in Visual Studio via Debug.Write:
And of course if you want to make simpler ones to use off the cuff, you can always extend ActionTextWriter... write the generic approach and reuse, right?
Run SQL Profiler if you have it. It'll show all traffic to your database, including SQL command text.
There is actually a very simple answer to your question
Just paste this in your watch window
Lots of people have been writing their own "DebugWriter" and attaching it like so:
This will output everything that Linq-to-Sql is doing into Visual Studio's debug window.