Table of Contents

Interface ISqlDatabaseChangeTracker

Namespace
LfrlAnvil.Sql.Objects.Builders
Assembly
LfrlAnvil.Sql.Core.dll

Represents a tracker of changes applied to the attached database builder.

public interface ISqlDatabaseChangeTracker
Extension Methods

Properties

ActionTimeout

Optional CommandTimeout for registered SqlDatabaseBuilderCommandAction instances.

TimeSpan? ActionTimeout { get; }

Property Value

TimeSpan?

ActiveObject

Represents a currently tracked SQL object builder instance, whose changes will be aggregated.

ISqlObjectBuilder? ActiveObject { get; }

Property Value

ISqlObjectBuilder

ActiveObjectExistenceState

Specifies the existence state of ActiveObject.

SqlObjectExistenceState ActiveObjectExistenceState { get; }

Property Value

SqlObjectExistenceState

Database

Database that this instance tracks.

ISqlDatabaseBuilder Database { get; }

Property Value

ISqlDatabaseBuilder

IsAttached

Specifies whether or not this change tracker is attached.

bool IsAttached { get; }

Property Value

bool

Remarks

Change tracker will ignore all changes when IsAttached is equal to false.

Mode

Specifies the current SqlDatabaseCreateMode.

SqlDatabaseCreateMode Mode { get; }

Property Value

SqlDatabaseCreateMode

Remarks

Change tracker will ignore all changes when Mode is equal to NoChanges.

Methods

AddAction(Action<IDbCommand>, Action<IDbCommand>?)

Adds a custom SqlDatabaseBuilderCommandAction to this change tracker.

ISqlDatabaseChangeTracker AddAction(Action<IDbCommand> action, Action<IDbCommand>? setup = null)

Parameters

action Action<IDbCommand>

Custom delegate that executes the IDbCommand.

setup Action<IDbCommand>

Optional delegate that prepares the IDbCommand. Can be used to e.g. prepare a collection of parameters. Equal to null by default.

Returns

ISqlDatabaseChangeTracker

this.

AddParameterizedStatement(ISqlStatementNode, IEnumerable<SqlParameter>, SqlParameterBinderCreationOptions?)

Adds a custom parameterized SQL statement to this change tracker.

ISqlDatabaseChangeTracker AddParameterizedStatement(ISqlStatementNode statement, IEnumerable<SqlParameter> parameters, SqlParameterBinderCreationOptions? options = null)

Parameters

statement ISqlStatementNode

SQL statement node to add.

parameters IEnumerable<SqlParameter>

Source of parameters to bind.

options SqlParameterBinderCreationOptions?

Optional SqlParameterBinderCreationOptions.

Returns

ISqlDatabaseChangeTracker

this.

AddParameterizedStatement<TSource>(ISqlStatementNode, TSource, SqlParameterBinderCreationOptions?)

Adds a custom parameterized SQL statement to this change tracker.

ISqlDatabaseChangeTracker AddParameterizedStatement<TSource>(ISqlStatementNode statement, TSource parameters, SqlParameterBinderCreationOptions? options = null) where TSource : notnull

Parameters

statement ISqlStatementNode

SQL statement node to add.

parameters TSource

Source of parameters to bind.

options SqlParameterBinderCreationOptions?

Optional SqlParameterBinderCreationOptions.

Returns

ISqlDatabaseChangeTracker

this.

Type Parameters

TSource

Parameter source type.

AddStatement(ISqlStatementNode)

Adds a custom SQL statement to this change tracker.

ISqlDatabaseChangeTracker AddStatement(ISqlStatementNode statement)

Parameters

statement ISqlStatementNode

SQL statement node to add.

Returns

ISqlDatabaseChangeTracker

this.

Exceptions

SqlObjectBuilderException

When statement contains parameters.

Attach(bool)

Changes IsAttached value for this change tracker.

ISqlDatabaseChangeTracker Attach(bool enabled = true)

Parameters

enabled bool

Value to set. Equal to true by default.

Returns

ISqlDatabaseChangeTracker

this.

CompletePendingChanges()

Completes all pending changes and registers appropriate SqlDatabaseBuilderCommandAction instances for them.

ISqlDatabaseChangeTracker CompletePendingChanges()

Returns

ISqlDatabaseChangeTracker

this.

ContainsChange(ISqlObjectBuilder, SqlObjectChangeDescriptor)

Checks whether or not a change for the given target and its property's descriptor is currently pending.

[Pure]
bool ContainsChange(ISqlObjectBuilder target, SqlObjectChangeDescriptor descriptor)

Parameters

target ISqlObjectBuilder

Object to check.

descriptor SqlObjectChangeDescriptor

Property change descriptor.

Returns

bool

true when the change is pending, otherwise false.

GetExistenceState(ISqlObjectBuilder)

Returns SqlObjectExistenceState value for the given ISqlObjectBuilder instance.

[Pure]
SqlObjectExistenceState GetExistenceState(ISqlObjectBuilder target)

Parameters

target ISqlObjectBuilder

Object to check.

Returns

SqlObjectExistenceState

One of three possible values:

  • Unchanged when target does not exist or a pending action for its creation or removal does not exist,
  • Created when pending creation action for target exists,
  • Removed when pending removal action for target exists.

Remarks

Use ActiveObjectExistenceState instead, for reading current state of the ActiveObject.

GetPendingActions()

Returns a collection of all pending SqlDatabaseBuilderCommandAction instances.

ReadOnlySpan<SqlDatabaseBuilderCommandAction> GetPendingActions()

Returns

ReadOnlySpan<SqlDatabaseBuilderCommandAction>

Collection of all pending SqlDatabaseBuilderCommandAction instances.

SetActionTimeout(TimeSpan?)

Changes ActionTimeout value for this change tracker.

ISqlDatabaseChangeTracker SetActionTimeout(TimeSpan? value)

Parameters

value TimeSpan?

Value to set.

Returns

ISqlDatabaseChangeTracker

this.

TryGetOriginalValue(ISqlObjectBuilder, SqlObjectChangeDescriptor, out object?)

Attempts to return a value before the change associated with the given target and its property's descriptor.

bool TryGetOriginalValue(ISqlObjectBuilder target, SqlObjectChangeDescriptor descriptor, out object? result)

Parameters

target ISqlObjectBuilder

Object to check.

descriptor SqlObjectChangeDescriptor

Property change descriptor.

result object

out parameter that returns the value before the change was made.

Returns

bool

true when the change is pending and original value was retrieved, otherwise false.