IDbCommandInterceptor查询监控

时间:2015-01-22 22:29:54

标签: entity-framework entity-framework-6

我在EF6中创建了一个查询拦截器:

public class QueryCommandInterceptor : IDbCommandInterceptor
{
    private readonly Stopwatch _stopWatch = new Stopwatch();

    public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
        {
            _stopWatch.Restart();
        }

        public void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
        {
            _stopWatch.Stop();
        }
}

两个Executing方法可以在相应的Executed方法完成之前启动吗?

1 个答案:

答案 0 :(得分:0)

你的意思是,这个IDbCommandInterceptor线程安全吗?

Is IDbCommandInterceptor in EntityFramework 6 thread safe

答案是否定的。