Reputation: 43
On many sites/blogs I noticed that people, who want to explain linq mechanism, write Linq Queries and provide SQL translation for that. How can I get the translation for my own queries? I'm working with EF .Net 4.0 in VS2010. Is there a place (property or even some third-party tool) where I can see what they're being translated into?
Upvotes: 2
Views: 534
Reputation: 96477
You can use the ObjectQuery.ToTraceString method:
var query = ...
string sql = ((System.Data.Objects.ObjectQuery)query).ToTraceString();
However, some shortcomings of this approach is that it will only show queries, not updates/inserts/deletes. Also, it won't reveal the parameters used.
If you need as much detail as possible from the query then use the SQL Server Profiler as Neil suggested.
Julie Lerman has a good article with different options on MSDN: Profiling Database Activity in the Entity Framework. She mentions:
Upvotes: 5
Reputation: 9318
You can use LinqPad, you can query your entity model and view the generated SQL.
Upvotes: 0
Reputation: 48547
The simplest method is to use SQL Profiler. I have found this a real god-send when it comes to debugging.
Upvotes: 4