有沒有辦法使用sql profiler for nmemory(內存數據庫)


我正在使用Entity Framework with Effort,它使用NMemory進行測試而不會產生實際的數據庫副作用。有沒有辦法查看被發送到nmemory數據庫的sql?

編輯:感謝@Gert_Arnold我一直在尋找DbContext.Database.Log。不幸的是我的輸出如下所示。任何人都可以評論這個嗎?我假設我得到這些空條目而不是我的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

熱門答案

您可以攔截並記錄命令。

 // 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 );

}

 }




許可下: CC-BY-SA
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因