我在项目中实现了 IDbCommandInterceptor 接口。我想登录其每个函数(ReaderExecuted,NonQueryExecuted等)。问题是“ DbCommand命令为空时是否存在这种情况?”在网上人们使用command?.CommandText的一些示例中,我想确保此代码不会成为“狗爪”。
public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
Logger(command, interceptionContext);
}
答案 0 :(得分:0)
我不这么认为,至少不是正常情况。 DbCommand class包含其自己的(非静态)执行方法和DbConnection does not,因此您需要一个DbCommand实例才能正常触发(I)DbCommandInterceptor处理程序。就是说,IDbCommandInterceptor只是一个接口,任何引用拦截器的人都可以使用null参数手动调用其任何公共方法。这取决于您期望人们使用您的代码的行为如何。