Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Way to view SQL executed by LINQ in Visual Studio? [duplicate]

This question already has an answer here:
view sql that linq-to-sql produces 3 Answers

I'm wondering if there is a way to see the T-SQL that was executed against the database in Visual Studio 2010 Ultimate when a LINQ to SQL query runs.

like image 427
l15a Avatar asked Jun 12 '12 18:06

l15a


People also ask

How can I see SQL generated by LINQ?

You can view the SQL code generated for queries and change processing by using the Log property. This approach can be useful for understanding LINQ to SQL functionality and for debugging specific problems.

How can I see the LINQ query in SQL Profiler?

Go to SQL Server Profiler and stop the trace, where you will see T-SQL statement of our stored procedure, as shown below. Notice that GetEmployees stored procedure is executed. Let's inspect C# method, which is generated by right clicking on the method, and go to the definition.


2 Answers

If you have Visual Studio Ultimate, you can see every SQL query your application runs in the IntelliTrace window while debugging.

like image 154
SLaks Avatar answered Oct 05 '22 10:10

SLaks


You have basically two options:

1.) use a profiler, there's one free made by AnjLab http://anjlab.com/en/projects/opensource/sqlprofiler

2.) use LinqPad (again a free solution) http://www.linqpad.net/

You really don't need Ultimate VS or anything paid like some people already suggested...

like image 43
walther Avatar answered Oct 05 '22 11:10

walther