Debugging Entity Framework SQL statements

For debugging EF queries, the easiest thing is to cast the query to ObjectQuery and use ToTraceString: var query = myContext.MyTable .Where(r => r.Id == searchId) .Select(r => r); Console.WriteLine(((ObjectQuery)query).ToTraceString()); This will show the underlying SQL for the query, and you can run the queries manually to debug why they are slow. Here is the … Read more