Class TableExtensions

Namespace
DbExport.Schema
Assembly
DbExport.Api.dll

Contains extension methods for performing various database operations on a Table object. These operations include generating SQL statements (SELECT, INSERT, UPDATE, DELETE), executing queries, and managing batch operations.

public static class TableExtensions
Inheritance
TableExtensions
Inherited Members

Methods

CopyTo(Table, DbConnection, QueryOptions, QueryOptions)

Copies data from the specified table to the target database connection using the provided query options.

public static void CopyTo(this Table table, DbConnection targetConnection, QueryOptions sourceOptions, QueryOptions targetOptions)

Parameters

table Table

The table from which data will be copied.

targetConnection DbConnection

The target database connection where the data will be inserted.

sourceOptions QueryOptions

The query options that define how data is read from the source table.

targetOptions QueryOptions

The query options that define how data is inserted into the target database.

Delete(Table, params object[])

Deletes a row from the specified table using the provided key values to identify the target row.

public static bool Delete(this Table table, params object[] keyValues)

Parameters

table Table

The table from which the row will be deleted.

keyValues object[]

An array of key values used to locate the row to delete.

Returns

bool

A boolean value indicating whether the deletion was successful.

DeleteBatch<TKey>(Table, IEnumerable<TKey>)

Deletes a batch of records from the specified table based on the provided key values.

public static bool DeleteBatch<TKey>(this Table table, IEnumerable<TKey> keyValues) where TKey : class, new()

Parameters

table Table

The table from which the records will be deleted.

keyValues IEnumerable<TKey>

A collection of key values identifying the records to be deleted.

Returns

bool

A boolean indicating whether the operation was successful.

Type Parameters

TKey

The type of the key used to identify records for deletion.

DeleteBatch<TKey>(Table, IEnumerable<TKey>, Action<DbCommand, TKey>)

Executes a batch delete operation for the specified table based on a collection of key values.

public static bool DeleteBatch<TKey>(this Table table, IEnumerable<TKey> keyValues, Action<DbCommand, TKey> keyBinder)

Parameters

table Table

The table from which records will be deleted.

keyValues IEnumerable<TKey>

The collection of key values representing the records to delete.

keyBinder Action<DbCommand, TKey>

A callback action to bind the key value to the database command parameters.

Returns

bool

A boolean value indicating whether the operation affected any records.

Type Parameters

TKey

The type of the key values used to identify the records to delete.

Delete<TKey>(Table, TKey)

Deletes a record from the specified table using the provided key value and binds the key to the using a default key binder.

public static bool Delete<TKey>(this Table table, TKey keyValue) where TKey : class, new()

Parameters

table Table

The table from which the record will be deleted.

keyValue TKey

The key value of the record to be deleted.

Returns

bool

A boolean value indicating whether the deletion was successful.

Type Parameters

TKey

The type of the key value used to identify the record to delete.

Delete<TKey>(Table, TKey, Action<DbCommand, TKey>)

Deletes a record from the specified table based on the provided key value and binds the key using the given key binder.

public static bool Delete<TKey>(this Table table, TKey keyValue, Action<DbCommand, TKey> keyBinder)

Parameters

table Table

The table from which the record will be deleted.

keyValue TKey

The key value identifying the record to delete.

keyBinder Action<DbCommand, TKey>

A delegate that binds the key value to a database command.

Returns

bool

A boolean indicating whether the record was successfully deleted.

Type Parameters

TKey

The type of the key used to identify the record to delete.

GenerateDelete(Table, string, QueryOptions)

Generates a SQL DELETE statement for the specified table using the given provider and query options.

public static string GenerateDelete(this Table table, string providerName, QueryOptions options)

Parameters

table Table

The table for which the DELETE statement will be generated.

providerName string

The name of the database provider, used to ensure compatibility when generating the SQL statement.

options QueryOptions

The query options that specify how the table name should be qualified and determine whether certain table features should be skipped.

Returns

string

A string containing the generated SQL DELETE statement.

GenerateInsert(Table, string, QueryOptions)

Generates a SQL INSERT statement for the specified table based on the provided query options.

public static string GenerateInsert(this Table table, string providerName, QueryOptions options)

Parameters

table Table

The table for which the INSERT statement will be generated.

providerName string

The name of the database provider used to format the SQL syntax.

options QueryOptions

The query options that determine which columns to include and whether to qualify the table name.

Returns

string

A string containing the generated SQL INSERT statement.

GenerateSelect(Table, Key, QueryOptions)

Generates a SQL SELECT statement for the specified table, filtering results based on the given key and applying the provided query options.

public static string GenerateSelect(this Table table, Key key, QueryOptions options)

Parameters

table Table

The table for which the SELECT statement will be generated.

key Key

The key defining the filter criteria for the SELECT statement.

options QueryOptions

The query options that specify how the statement should be generated, including conditions and table name qualification.

Returns

string

A string containing the generated SQL SELECT statement with the applied key filter.

GenerateSelect(Table, QueryOptions)

Generates a SQL SELECT statement for the specified table based on the provided query options.

public static string GenerateSelect(this Table table, QueryOptions options)

Parameters

table Table

The table for which the SELECT statement will be generated.

options QueryOptions

The query options that define which columns to include and how the table name should be qualified.

Returns

string

A string containing the generated SQL SELECT statement.

GenerateUpdate(Table, string, QueryOptions)

Generates a SQL UPDATE statement for the specified table, including the columns to update and the primary key for filtering.

public static string GenerateUpdate(this Table table, string providerName, QueryOptions options)

Parameters

table Table

The table for which the UPDATE statement will be generated.

providerName string

The name of the database provider being used, which determines SQL syntax specifics.

options QueryOptions

The query options that define which columns to include and whether to qualify the table name.

Returns

string

A string containing the generated SQL UPDATE statement.

Insert(Table, params object[])

Inserts a new row into the specified table using the provided values.

public static bool Insert(this Table table, params object[] rowValues)

Parameters

table Table

The table where the data will be inserted.

rowValues object[]

An array of values representing the data for the row to be inserted.

Returns

bool

A boolean value indicating whether the insert operation was successful.

InsertBatch<TRow>(Table, IEnumerable<TRow>)

Inserts a batch of rows into the specified table using the provided row values and a default row binding implementation.

public static bool InsertBatch<TRow>(this Table table, IEnumerable<TRow> rowValues) where TRow : class, new()

Parameters

table Table

The table into which the rows will be inserted.

rowValues IEnumerable<TRow>

The collection of row values to be inserted into the table.

Returns

bool

True if the batch insert operation succeeds; otherwise, false.

Type Parameters

TRow

The type of the rows being inserted. Must be a class and have a parameterless constructor.

InsertBatch<TRow>(Table, IEnumerable<TRow>, Action<DbCommand, TRow>)

Inserts a batch of rows into the specified table using the provided binding logic to map rows to database parameters.

public static bool InsertBatch<TRow>(this Table table, IEnumerable<TRow> rowValues, Action<DbCommand, TRow> rowBinder)

Parameters

table Table

The target table into which the rows will be inserted.

rowValues IEnumerable<TRow>

The collection of data rows to insert into the table.

rowBinder Action<DbCommand, TRow>

The callback function responsible for binding each row to the database command parameters.

Returns

bool

A boolean value indicating whether the batch insert operation affected any rows.

Type Parameters

TRow

The type of the data rows to be inserted.

Insert<TRow>(Table, TRow)

Inserts a row into the specified table using the provided row data and a default row binder.

public static bool Insert<TRow>(this Table table, TRow rowValue) where TRow : class, new()

Parameters

table Table

The table into which the row will be inserted.

rowValue TRow

The data for the row to be inserted.

Returns

bool

A boolean indicating whether the row was successfully inserted.

Type Parameters

TRow

The type of the row data to be inserted, which must be a class with a parameterless constructor.

Insert<TRow>(Table, TRow, Action<DbCommand, TRow>)

Inserts a new row into the specified table using the provided row value and a custom row binder action.

public static bool Insert<TRow>(this Table table, TRow rowValue, Action<DbCommand, TRow> rowBinder)

Parameters

table Table

The table where the row will be inserted.

rowValue TRow

The value of the row to insert.

rowBinder Action<DbCommand, TRow>

A delegate that binds the row value to a database command.

Returns

bool

A boolean indicating whether the insertion was successful.

Type Parameters

TRow

The type of the row object to be inserted.

OpenReader(Table, QueryOptions)

Opens a data reader for the specified table using the provided query options.

public static DbDataReader OpenReader(this Table table, QueryOptions options)

Parameters

table Table

The table for which the data reader will be opened.

options QueryOptions

The query options that define how the SELECT statement should be generated.

Returns

DbDataReader

A DbDataReader instance to read the rows retrieved from the specified table. The connection will automatically close when the reader is disposed.

Select<TRow>(Table)

Returns a list of entities of the specified type, mapped from the rows in the table.

public static List<TRow> Select<TRow>(this Table table) where TRow : class, new()

Parameters

table Table

The table from which data will be selected and mapped to entities.

Returns

List<TRow>

A list of entities of the specified type, representing the data from the table.

Type Parameters

TRow

The type of entity to which each row in the table will be mapped. Must be a class with a parameterless constructor.

Select<TRow>(Table, Key, params object[])

Retrieves a list of entities of type TRow from the specified table based on the provided key and key values.

public static List<TRow> Select<TRow>(this Table table, Key key, params object[] keyValues) where TRow : class, new()

Parameters

table Table

The table from which to select rows.

key Key

The key that defines the criteria used for selection.

keyValues object[]

The values of the key to be used as the selection criteria.

Returns

List<TRow>

A list of entities of type TRow representing the selected rows.

Type Parameters

TRow

The entity type of the rows to be retrieved. Must be a class with a parameterless constructor.

Select<TRowSet>(Table, Func<DbDataReader, TRowSet>)

Executes a SQL SELECT query on the specified table and processes the result set using the provided extractor function.

public static TRowSet Select<TRowSet>(this Table table, Func<DbDataReader, TRowSet> extractor)

Parameters

table Table

The table on which the SELECT query will be executed.

extractor Func<DbDataReader, TRowSet>

A function that processes the data reader and extracts the result set.

Returns

TRowSet

The result set created by the extractor function based on the query output.

Type Parameters

TRowSet

The type of the result set that will be created from the query.

Select<TRowSet, TKey>(Table, Key, TKey, Action<DbCommand, TKey>, Func<DbDataReader, TRowSet>)

Executes a SQL SELECT query for the specified table and key and maps the result set to a custom type using the provided key binder and data extraction function.

public static TRowSet Select<TRowSet, TKey>(this Table table, Key key, TKey keyValue, Action<DbCommand, TKey> keyBinder, Func<DbDataReader, TRowSet> extractor)

Parameters

table Table

The table for which the SELECT query will be executed.

key Key

The key used to filter the query results.

keyValue TKey

The value of the key to use with the SELECT query.

keyBinder Action<DbCommand, TKey>

A function that binds the key value to the database command parameters.

extractor Func<DbDataReader, TRowSet>

A function that extracts data from the query results and maps it to the specified type.

Returns

TRowSet

An instance of TRowSet containing the extracted query results.

Type Parameters

TRowSet

The type into which the query results will be mapped.

TKey

The type of the key value used for query filtering.

UpdateBatch<TRow>(Table, IEnumerable<TRow>)

Updates a batch of rows in the specified table using the provided collection of row values and a default entity-to-command binder.

public static bool UpdateBatch<TRow>(this Table table, IEnumerable<TRow> rowValues) where TRow : class, new()

Parameters

table Table

The table where the batch update will be applied.

rowValues IEnumerable<TRow>

The collection of row values to be updated in the table.

Returns

bool

True if the batch update is successful; otherwise, false.

Type Parameters

TRow

The type of the rows in the collection, which must be a reference type with a parameterless constructor.

UpdateBatch<TRow>(Table, IEnumerable<TRow>, Action<DbCommand, TRow>)

Updates a batch of rows in the specified table using the provided row values and a function to bind parameter values to the command.

public static bool UpdateBatch<TRow>(this Table table, IEnumerable<TRow> rowValues, Action<DbCommand, TRow> rowBinder)

Parameters

table Table

The table where the rows will be updated.

rowValues IEnumerable<TRow>

The collection of row values to update the table with.

rowBinder Action<DbCommand, TRow>

The function that binds parameter values to the database command object for each row.

Returns

bool

A boolean value indicating whether the batch update affected any rows.

Type Parameters

TRow

The type of the objects representing the rows to be updated.

Update<TRow>(Table, TRow)

Updates the specified table with the provided row data.

public static bool Update<TRow>(this Table table, TRow rowValue) where TRow : class, new()

Parameters

table Table

The table to be updated.

rowValue TRow

The object containing the data to update the table with.

Returns

bool

A boolean indicating whether the update operation was successful.

Type Parameters

TRow

The type of the row data. Must be a reference type with a parameterless constructor.

Update<TRow>(Table, TRow, Action<DbCommand, TRow>)

Executes an update operation on the specified table using the given row value and a binding action to populate parameter values.

public static bool Update<TRow>(this Table table, TRow rowValue, Action<DbCommand, TRow> rowBinder)

Parameters

table Table

The table on which the update operation will be executed.

rowValue TRow

The row data containing the values to be updated.

rowBinder Action<DbCommand, TRow>

An action that binds the provided row data to the parameters of the database command.

Returns

bool

A boolean value indicating whether the update operation affected one or more rows.

Type Parameters

TRow

The type of the row value being updated.