Entity Framework How to see SQL statements for SaveChanges method
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.
See http://msdn.microsoft.com/en-US/data/dn469464
In general you can hook up the built-in tracer or any logger by simple
context.Database.Log = msg => Trace.WriteLine(msg);
in the DbContext constructor. See more in MSDN. Some other approaches from MS are here (all based on DataContext.Log property).
Talking about the Clutch solution mentioned by Nate, it doesn't work with EF v6 (see this bug-report).
REFERENCES
- Logging and Intercepting Database Operations (EF6 Onwards)
- Logging and Intercepting Database Operations