Show SQL generated by LinqtoSQL
How would one go about seeing the SQL generated by a LINQ2SQL insert? Let's say that I have
is there anyway to see the SQL? I've installed the LINQtoSQL visualizer Scott Gu mentions (http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx) and it does seem to work for full LINQ queries but not for inserts such as this.
You can use DataContext.Log to log the SQL. You can set any TextWriter to the DataContext.Log property. If you want to log output to your debugger or console, try this http://www.u2u.info/Blogs/Kris/Lists/Posts/Post.aspx?ID=11 - and you're good to go.
The SQL Server Profiler will show you the generated queries. It will also show you the execution plans that the SQL Server uses to solve those queries, and provide you with ways to improve performance.
More info at http://msdn.microsoft.com/en-us/library/ms187929.aspx