一、DataContext本身有提供Log属性来将LINQ to SQL生成的SQL语句格式化并输出到控制台窗口, 通常是这样:



就可以在启动Debug调试的时候将Log信息发送到Debug的output窗口了, 非常方便, 强力推荐你使用.关于这个工具类的更多细节, 点这里查看 。
二、可以看到所能生成的 SQL 语句了,Debug过程中想查看结果怎么办,大牛ScottGu为我们准备了个好东东,参看http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx
工具下载:http://www.scottgu.com/blogposts/linqquery/SqlServerQueryVisualizer.zip
安装方法
1. 关闭 VS2008。
2. 将压缩包中的 SqlServerQueryVisualizer.dll 拷贝到 \Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\Visualizers。
3. 重启 VS2008 即可。