Is there a way to use a sql profiler for nmemory (an in-memory database)


Question

I'm using Entity Framework with Effort that uses NMemory to test without having actual database side-effects. Is there any way to view the sql that's being sent to the nmemory database?

Edit: Thanks to @Gert_Arnold I have been looking in to DbContext.Database.Log. Unfortunately my output looks like below. Can anyone comment on this? I'm assuming I'm getting these null entries instead of my sql.

Opened connection at 4/27/2015 11:08:22 AM -05:00
Started transaction at 4/27/2015 11:08:22 AM -05:00
<null>
-- Executing at 4/27/2015 11:08:23 AM -05:00
-- Completed in 132 ms with result: 1

<null>
-- Executing at 4/27/2015 11:08:23 AM -05:00
-- Completed in 5 ms with result: 1

Committed transaction at 4/27/2015 11:08:23 AM -05:00
Closed connection at 4/27/2015 11:08:23 AM -05:00
Disposed transaction at 4/27/2015 11:08:23 AM -05:00
Opened connection at 4/27/2015 11:08:24 AM -05:00
Started transaction at 4/27/2015 11:08:24 AM -05:00
<null>
-- Executing at 4/27/2015 11:08:24 AM -05:00
-- Completed in 8 ms with result: 1

Committed transaction at 4/27/2015 11:08:24 AM -05:00
Closed connection at 4/27/2015 11:08:24 AM -05:00
Disposed transaction at 4/27/2015 11:08:24 AM -05:00

Popular Answer

You can intercept and log the commands.

 // Before command is sent tell EF about the new interceptor
 DbInterception.Add(new MyEFDbInterceptor());


// The interceptor class is called by , see the various interface methods
// just a couple shown here.
public class MyEFDbInterceptor: IDbCommandInterceptor   {
  public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)    {
     Debug.Writeln(command.CommandText );
     //Debug.Writeln(interceptionContext.Result ); // might be interesting use
}

 public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
  Debug.Writeln(command.CommandText );

}

 }




Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why