Link Search Menu Expand Document

CancellableTraceLog


A trace-logging class that is being used to cancel the existing operation. It is used in all BEFORE methods of the ITrace object. It derives from TraceLog class.

Properties

Below is the list of properties.

NameDescription
IsCancelled`Is used to determine whether the operation has been cancelled.
IsThrowExceptionIs used to determine whether an exception will be thrown back to the actual operation.
ParameterHandles the parameters of the execution.
StatementHandles the actual SQL statement generated by the library.

Methods

Below is the list of methods.

NameDescription
CancelIs used to cancel the actual operation. It accepts the throwException argument to define whether an exception will be thrown back to the operation during cancellation.

Implementation

Let us say you have a custom trace class named MyCustomTrace. Then, you pass this object when you call the Insert operation.

using (var connection = new SqlConnection(connectionString))
{
    connection.Insert<Person>(person, trace: new MyCustomTrace());
}

You can set a breakpoint at your MyCustomTrace.BeforeExecution() method and can call the Cancel() method to cancel the operation.

public void BeforeExecution(CancellableTraceLog log)
{
    if (log.Statement.IndexOf("INSERT") <= 0)
    {
        log.Cancel(true);
    }
}

By setting the throwException argument to true, an exception will be thrown back to the actual operation.