Table of Contents

Interface IDataMerge

Namespace
FluentCommand.Merge
Assembly
FluentCommand.SqlServer.dll

A fluent interface for configuring and executing a DataMerge operation.

public interface IDataMerge
Extension Methods

Methods

CommandTimeout(int)

Sets the wait time (in seconds) before terminating the attempt to execute the command and generating an error.

IDataMerge CommandTimeout(int timeout)

Parameters

timeout int

The time in seconds to wait for the command to execute.

Returns

IDataMerge

The same IDataMerge instance for fluent chaining.

Execute(DataTable)

Merges the specified tableData into the target table.

int Execute(DataTable tableData)

Parameters

tableData DataTable

The DataTable containing the data to be merged.

Returns

int

The number of rows processed.

Exceptions

InvalidOperationException

Bulk-Copy is only supported by SQL Server. Ensure DataSession was created with a valid SqlConnection.

ValidationException

Thrown if the merge definition is invalid:

  • TargetTable is required.
  • At least one column is required.
  • At least one column must be marked as a key.
  • SourceColumn is required for column mapping.
  • NativeType is required for column mapping.

ExecuteAsync(DataTable, CancellationToken)

Asynchronously merges the specified tableData into the target table.

Task<int> ExecuteAsync(DataTable tableData, CancellationToken cancellationToken = default)

Parameters

tableData DataTable

The DataTable containing the data to be merged.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<int>

A task representing the asynchronous operation. The result contains the number of rows processed.

Exceptions

InvalidOperationException

Bulk-Copy is only supported by SQL Server. Ensure DataSession was created with a valid SqlConnection.

ValidationException

Thrown if the merge definition is invalid:

  • TargetTable is required.
  • At least one column is required.
  • At least one column must be marked as a key.
  • SourceColumn is required for column mapping.
  • NativeType is required for column mapping.

ExecuteAsync<TEntity>(IEnumerable<TEntity>, CancellationToken)

Asynchronously merges the specified data into the target table.

Task<int> ExecuteAsync<TEntity>(IEnumerable<TEntity> data, CancellationToken cancellationToken = default) where TEntity : class

Parameters

data IEnumerable<TEntity>

The data to be merged.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<int>

A task representing the asynchronous operation. The result contains the number of rows processed.

Type Parameters

TEntity

The type of the entity being merged.

ExecuteOutput(DataTable)

Merges the specified table into the target table and returns the output rows describing the changes.

IEnumerable<DataMergeOutputRow> ExecuteOutput(DataTable table)

Parameters

table DataTable

The DataTable containing the data to be merged.

Returns

IEnumerable<DataMergeOutputRow>

A collection of DataMergeOutputRow instances describing the merge results.

Exceptions

InvalidOperationException

Bulk-Copy is only supported by SQL Server. Ensure DataSession was created with a valid SqlConnection.

ValidationException

Thrown if the merge definition is invalid:

  • TargetTable is required.
  • At least one column is required.
  • At least one column must be marked as a key.
  • SourceColumn is required for column mapping.
  • NativeType is required for column mapping.

ExecuteOutputAsync(DataTable, CancellationToken)

Asynchronously merges the specified table into the target table and returns the output rows describing the changes.

Task<IEnumerable<DataMergeOutputRow>> ExecuteOutputAsync(DataTable table, CancellationToken cancellationToken = default)

Parameters

table DataTable

The DataTable containing the data to be merged.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<IEnumerable<DataMergeOutputRow>>

A task representing the asynchronous operation. The result contains a collection of DataMergeOutputRow instances describing the merge results.

Exceptions

InvalidOperationException

Bulk-Copy is only supported by SQL Server. Ensure DataSession was created with a valid SqlConnection.

ValidationException

Thrown if the merge definition is invalid:

  • TargetTable is required.
  • At least one column is required.
  • At least one column must be marked as a key.
  • SourceColumn is required for column mapping.
  • NativeType is required for column mapping.

ExecuteOutputAsync<TEntity>(IEnumerable<TEntity>, CancellationToken)

Asynchronously merges the specified data into the target table and returns the output rows describing the changes.

Task<IEnumerable<DataMergeOutputRow>> ExecuteOutputAsync<TEntity>(IEnumerable<TEntity> data, CancellationToken cancellationToken = default) where TEntity : class

Parameters

data IEnumerable<TEntity>

The data to be merged.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<IEnumerable<DataMergeOutputRow>>

A task representing the asynchronous operation. The result contains a collection of DataMergeOutputRow instances describing the merge results.

Type Parameters

TEntity

The type of the entity being merged.

ExecuteOutput<TEntity>(IEnumerable<TEntity>)

Merges the specified data into the target table and returns the output rows describing the changes.

IEnumerable<DataMergeOutputRow> ExecuteOutput<TEntity>(IEnumerable<TEntity> data) where TEntity : class

Parameters

data IEnumerable<TEntity>

The data to be merged.

Returns

IEnumerable<DataMergeOutputRow>

A collection of DataMergeOutputRow instances describing the merge results.

Type Parameters

TEntity

The type of the entity being merged.

Execute<TEntity>(IEnumerable<TEntity>)

Merges the specified data into the target table.

int Execute<TEntity>(IEnumerable<TEntity> data) where TEntity : class

Parameters

data IEnumerable<TEntity>

The data to be merged.

Returns

int

The number of rows processed.

Type Parameters

TEntity

The type of the entity being merged.

IdentityInsert(bool)

Specifies whether to allow identity insert on the target table during the merge operation.

IDataMerge IdentityInsert(bool value = true)

Parameters

value bool

true to allow identity insert on the target table; otherwise, false.

Returns

IDataMerge

The same IDataMerge instance for fluent chaining.

IncludeDelete(bool)

Specifies whether to delete data from the target table that is not found in the source data during the merge operation.

IDataMerge IncludeDelete(bool value = true)

Parameters

value bool

true to delete rows in the target table not present in the source data; otherwise, false.

Returns

IDataMerge

The same IDataMerge instance for fluent chaining.

IncludeInsert(bool)

Specifies whether to insert data not found in the target table during the merge operation.

IDataMerge IncludeInsert(bool value = true)

Parameters

value bool

true to insert data not found in the target table; otherwise, false.

Returns

IDataMerge

The same IDataMerge instance for fluent chaining.

IncludeUpdate(bool)

Specifies whether to update data found in the target table during the merge operation.

IDataMerge IncludeUpdate(bool value = true)

Parameters

value bool

true to update data found in the target table; otherwise, false.

Returns

IDataMerge

The same IDataMerge instance for fluent chaining.

Map(Action<DataMergeMapping>)

Begins mapping the columns to merge using the provided fluent mapping builder.

IDataMerge Map(Action<DataMergeMapping> builder)

Parameters

builder Action<DataMergeMapping>

A delegate to configure the data column mappings using a DataMergeMapping instance.

Returns

IDataMerge

The same IDataMerge instance for fluent chaining.

Map<TEntity>(Action<DataMergeMapping<TEntity>>)

Begins mapping the columns to merge using a strongly typed fluent mapping builder.

IDataMerge Map<TEntity>(Action<DataMergeMapping<TEntity>> builder) where TEntity : class

Parameters

builder Action<DataMergeMapping<TEntity>>

A delegate to configure the data column mappings using a DataMergeMapping<TEntity> instance.

Returns

IDataMerge

The same IDataMerge instance for fluent chaining.

Type Parameters

TEntity

The type of the entity being merged.

Mode(DataMergeMode)

Sets the mode for how the merge will be processed.

IDataMerge Mode(DataMergeMode mergeMode)

Parameters

mergeMode DataMergeMode

The merge mode to use. See DataMergeMode for options.

Returns

IDataMerge

The same IDataMerge instance for fluent chaining.

TargetTable(string)

Sets the name of the target table to merge data into.

IDataMerge TargetTable(string value)

Parameters

value string

The name of the target table.

Returns

IDataMerge

The same IDataMerge instance for fluent chaining.