I used to use the context.Log for tracing LINQ to SQL generated SQL Statements as shown in Sql Server Query Visualizer â€“ Cannot see generated SQL Query
context.Log = new OutputWindowWriter();
For EF, is there anything similar and easy like the above approach?
In general you can hook up the built-in tracer or any logger by simple
context.Database.Log = msg => Trace.WriteLine(msg);
The Clutch.Diagnostics.EntityFramework (available in NuGet) works perfectly for me, and it's simpler than the EFTracingProvider.
UPDATE for EF 6:
Starting with Entity Framework 6, anytime Entity Framework sends a command to the database this command can be intercepted by application code. This is most commonly used for logging SQL, but can also be used to modify or abort the command.
Specifically, EF includes:
* A Log property for the context similar to DataContext.Log in LINQ to SQL.
* A mechanism to customize the content and formatting of the output sent to the log.
* Low-level building blocks for interception giving greater control/flexibility.