What is the most efficient way to get the sql query from EF? I need this so I can run the query analysis and find its execution plan.
I know I can hook profiler to SQL server, but this step is a pain and a tremendous hit on productivity, almost enough to give up ORM altogether.
Is there a better, more efficient way to optimize EF queries?
Yes, buy EF Profiler or Huagati Profiler. Alternatively use EF Provider wrapper for tracing.
Profiler is only half of the story. There is also Database Engine Tuning Advisor and these tools are the main tool set if you really want to optimize SQL queries – but optimizing SQL queries you don’t have under your control is very hard and sometimes impossible.