私は EF 6 を使用しており、System.Data.Entity.Infrastructure.Interception 名前空間から IDbCommandInterceptor を使用しようとしています。
読み取りと更新にはうまく機能しますが、新しいエンティティをデータベースに追加すると、NonQueryExecuted() も NonQueryExecuting() も起動しません。これは Interceptor による通常の動作ですか、それとも私の側で何かが正しく実装されていませんか?
コード:
インターセプター:
public void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
this.MonitorAndNotifySignalRService(command);
}
public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
{
}
public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
}
public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
{
}
public void ScalarExecuted(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
{
}
public void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
{
}
データコンテキストベース:
static Constructor()
{
Database.SetInitializer<TDataContext>(null); // turn off database initialization so the db schema is not changed from the model
DbInterception.Add(new Interceptor());
}