What is the minimal amount of code I can write to get a single callback from EF 4.1 that provides the following:
OnSQLExecuted(DbCommand cmd, DateTime s
The easiest way is to use the Entity Framework tracing wrappers and hook into the EFTracingConnection
's CommandFinished
. It doesn't give you the start time, but it does give you the duration (which, subtracted from Now
, is likely close enough).
I'd call the code impact "moderate", since you do have to change references to the existing context class. It's pretty straightforward, though.
If you just want tracing and don't need the actual callback, the NuGet package has a simple default tracing system.
Edit (stack trace added): The EF tracing wrappers don't give you the stack trace. You can get the source and add it without too much difficulty, but I'd think that would impact performance.