SQL from Linq to Entity Framework
Problem: how do I tell what SQL does Linq to Entity Framework generates?
If you are using SQL Server its easy. You start the SQL Profiler and you are done. If you are using Oracle the task is not so easy. You can:
1. start the trace on the Oracle server and get the huge barely readable text file physically on the server and use TKPROF
2. look up the lat SQL query from session using the Enterprise Manager-Konsole
3. buy a 3rd party tool like FlexTracer to trace the OCI communication.
Well yeah! Not fun.
But there is another option inside Entity Framework itself! It is not quite obvious, so it took me a little to figure it out:
((System.Data.Objects.ObjectQuery)Query).ToTraceString()
where Query is something like System.Linq.IQueryable<T>.