有没有办法使用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合法吗? 是的,了解原因