Debugging Entity Framework With ToTraceString

When you develop with Entity Framework, you may need the SQL instruction passed to the SQL engine when your LINQ query is evaluated.

As you can see from the post ToTraceString Method in Entity Framework, both the System.Data.Objects.ObjectQuery and the System.Data.EntityClient.EntityCommand classed implement the ToTraceString() method, whose evaluation returs just the info you need.


An update in EF 6.1 allows to output the generated SQL doing:

   context.Database.Log = Console.Write; 

after having created the context, as explained in Logging and Intercepting Database Operations.

Comments (2) -

  • How did you get your information about Visual Studio 2010.
    • Hi Robbie,
      In older versions of Entity Framework, you have to use the first way, i.e. using the ToTraceString() method

Pingbacks and trackbacks (3)+

Add comment

Loading