stimms
stimms

Reputation: 44094

Show SQL generated by LinqtoSQL

How would one go about seeing the SQL generated by a LINQ2SQL insert? Let's say that I have

        db.Elephants.InsertOnSubmit(elephantInstance);
        db.SubmitChanges();

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.

Upvotes: 1

Views: 522

Answers (2)

Richard Anthony Hein
Richard Anthony Hein

Reputation: 10650

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.

Upvotes: 1

Robert Harvey
Robert Harvey

Reputation: 180908

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

Upvotes: 1

Related Questions