1

Other than using profiler, is there a way to view the sql that linq-to-sql produces?

mrblah
  • 99,669
  • 140
  • 310
  • 420

3 Answers3

2

I used LinqPad today to help debug a Linq2Sql issue. It's a neat little tool, and will show you the SQL you're generating also.

http://www.linqpad.net/

Jason
  • 86,222
  • 15
  • 131
  • 146
0

You can use the Log property on the DataContext to write out what the SQL is. This takes a TextWriter and is pretty easy to use. If you need an example I can provide you one.

DataContext Log

SteveM
  • 492
  • 3
  • 9
0

Your Linq-to-Sql query will be stored in a variable. You can hover over this variable to inspect it and it will show you the generated SQL.

Another method is to output it using the following code:

Console.WriteLine(dbContext.GetCommand(yourQuery).CommandText);

And of course Profiler which you already know about.

Kelsey
  • 47,246
  • 16
  • 124
  • 162
  • @meblah if this answer or another helped you, you should set an accepted answer so that others reading this question can locate the solution that helped you. – Kelsey Aug 18 '10 at 16:08