How can I see the SQL generated from a LINQ to SQL query?

How can I see the SQL generated from a LINQ to SQL query? The obvious answer is to open the SQL profiler and view it there. Is there a way in VS?

Maybe there is a VS add-in similar to the visualizer that allows you to hover over the DataContext to view SQL.

+3
source share
3 answers

Yes, you can rate:

query.Expression.ToString()

You can also see this line in the Visual Studio debugger when checking a query variable. You do not need a plugin.

Note that this is a query property, not a DataContext.

+5
source

TextWriter ( -, TextWriter, ) Log DataContext. SQL Server, TextWriter, Log.

, , DataContext.

+2

In addition to @Mark's answer, you can look at LINQPad , which can be useful if you write a large amount of LINQ queries.

+1
source

Source: https://habr.com/ru/post/1733273/


All Articles