Table of Contents

Interface ICommandInterceptor

Namespace
LinqToDB.Interceptors
Assembly
linq2db.dll
public interface ICommandInterceptor : IInterceptor
Extension Methods

Methods

AfterExecuteReader(CommandEventData, DbCommand, CommandBehavior, DbDataReader)

Event, triggered after command execution using ExecuteReader(CommandBehavior) or ExecuteReaderAsync(CommandBehavior, CancellationToken) methods.

void AfterExecuteReader(CommandEventData eventData, DbCommand command, CommandBehavior commandBehavior, DbDataReader dataReader)

Parameters

eventData CommandEventData

Additional data for event.

command DbCommand

Executed command.

commandBehavior CommandBehavior

Behavior, used for command execution.

dataReader DbDataReader

DbDataReader instance, returned by ExecuteReader(CommandBehavior) or ExecuteReaderAsync(CommandBehavior, CancellationToken) methods.

BeforeReaderDispose(CommandEventData, DbCommand?, DbDataReader)

Event, triggered after all data is consumed from DbDataReader before Dispose() call.

void BeforeReaderDispose(CommandEventData eventData, DbCommand? command, DbDataReader dataReader)

Parameters

eventData CommandEventData

Additional data for event.

command DbCommand

Executed command. Could be null.

dataReader DbDataReader

DbDataReader instance.

BeforeReaderDisposeAsync(CommandEventData, DbCommand?, DbDataReader)

Event, triggered after all data is consumed from DbDataReader before DisposeAsync call.

Task BeforeReaderDisposeAsync(CommandEventData eventData, DbCommand? command, DbDataReader dataReader)

Parameters

eventData CommandEventData

Additional data for event.

command DbCommand

Executed command. Could be null.

dataReader DbDataReader

DbDataReader instance.

Returns

Task

CommandInitialized(CommandEventData, DbCommand)

Event, triggered after command prepared for execution with both command text and parameters set.

DbCommand CommandInitialized(CommandEventData eventData, DbCommand command)

Parameters

eventData CommandEventData

Additional data for event.

command DbCommand

Initialized command instance.

Returns

DbCommand

Returns command instance for execution.

ExecuteNonQuery(CommandEventData, DbCommand, Option<int>)

Event, triggered before command execution using ExecuteNonQuery() method.

Option<int> ExecuteNonQuery(CommandEventData eventData, DbCommand command, Option<int> result)

Parameters

eventData CommandEventData

Additional data for event.

command DbCommand

Command, prepared for execution.

result Option<int>

Value, returned by previous interceptor when multiple ICommandInterceptor instances registered or None.

Returns

Option<int>

When event returns None, Linq To DB will execute command, otherwise it will use returned value as execution result.

ExecuteNonQueryAsync(CommandEventData, DbCommand, Option<int>, CancellationToken)

Event, triggered before command execution using ExecuteNonQueryAsync(CancellationToken) method.

Task<Option<int>> ExecuteNonQueryAsync(CommandEventData eventData, DbCommand command, Option<int> result, CancellationToken cancellationToken)

Parameters

eventData CommandEventData

Additional data for event.

command DbCommand

Command, prepared for execution.

result Option<int>

Value, returned by previous interceptor when multiple ICommandInterceptor instances registered or None.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<Option<int>>

When event returns None, Linq To DB will execute command, otherwise it will use returned value as execution result.

ExecuteReader(CommandEventData, DbCommand, CommandBehavior, Option<DbDataReader>)

Event, triggered before command execution using ExecuteReader(CommandBehavior) method.

Option<DbDataReader> ExecuteReader(CommandEventData eventData, DbCommand command, CommandBehavior commandBehavior, Option<DbDataReader> result)

Parameters

eventData CommandEventData

Additional data for event.

command DbCommand

Command, prepared for execution.

commandBehavior CommandBehavior

Behavior, used for command execution.

result Option<DbDataReader>

Value, returned by previous interceptor when multiple ICommandInterceptor instances registered or None.

Returns

Option<DbDataReader>

When event returns None, Linq To DB will execute command, otherwise it will use returned value as execution result.

ExecuteReaderAsync(CommandEventData, DbCommand, CommandBehavior, Option<DbDataReader>, CancellationToken)

Event, triggered before command execution using ExecuteReaderAsync(CommandBehavior, CancellationToken) method.

Task<Option<DbDataReader>> ExecuteReaderAsync(CommandEventData eventData, DbCommand command, CommandBehavior commandBehavior, Option<DbDataReader> result, CancellationToken cancellationToken)

Parameters

eventData CommandEventData

Additional data for event.

command DbCommand

Command, prepared for execution.

commandBehavior CommandBehavior

Behavior, used for command execution.

result Option<DbDataReader>

Value, returned by previous interceptor when multiple ICommandInterceptor instances registered or None.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<Option<DbDataReader>>

When event returns None, Linq To DB will execute command, otherwise it will use returned value as execution result.

ExecuteScalar(CommandEventData, DbCommand, Option<object?>)

Event, triggered before command execution using ExecuteScalar() method.

Option<object?> ExecuteScalar(CommandEventData eventData, DbCommand command, Option<object?> result)

Parameters

eventData CommandEventData

Additional data for event.

command DbCommand

Command, prepared for execution.

result Option<object>

Value, returned by previous interceptor when multiple ICommandInterceptor instances registered or None.

Returns

Option<object>

When event returns None, Linq To DB will execute command, otherwise it will use returned value as execution result.

ExecuteScalarAsync(CommandEventData, DbCommand, Option<object?>, CancellationToken)

Event, triggered before command execution using ExecuteScalarAsync(CancellationToken) method.

Task<Option<object?>> ExecuteScalarAsync(CommandEventData eventData, DbCommand command, Option<object?> result, CancellationToken cancellationToken)

Parameters

eventData CommandEventData

Additional data for event.

command DbCommand

Command, prepared for execution.

result Option<object>

Value, returned by previous interceptor when multiple ICommandInterceptor instances registered or None.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<Option<object>>

When event returns None, Linq To DB will execute command, otherwise it will use returned value as execution result.