Class TableExtensions
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
tableTableThe table from which data will be copied.
targetConnectionDbConnectionThe target database connection where the data will be inserted.
sourceOptionsQueryOptionsThe query options that define how data is read from the source table.
targetOptionsQueryOptionsThe 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
tableTableThe table from which the row will be deleted.
keyValuesobject[]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
tableTableThe table from which the records will be deleted.
keyValuesIEnumerable<TKey>A collection of key values identifying the records to be deleted.
Returns
- bool
A boolean indicating whether the operation was successful.
Type Parameters
TKeyThe 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
tableTableThe table from which records will be deleted.
keyValuesIEnumerable<TKey>The collection of key values representing the records to delete.
keyBinderAction<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
TKeyThe 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
tableTableThe table from which the record will be deleted.
keyValueTKeyThe key value of the record to be deleted.
Returns
- bool
A boolean value indicating whether the deletion was successful.
Type Parameters
TKeyThe 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
tableTableThe table from which the record will be deleted.
keyValueTKeyThe key value identifying the record to delete.
keyBinderAction<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
TKeyThe 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
tableTableThe table for which the DELETE statement will be generated.
providerNamestringThe name of the database provider, used to ensure compatibility when generating the SQL statement.
optionsQueryOptionsThe 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
tableTableThe table for which the INSERT statement will be generated.
providerNamestringThe name of the database provider used to format the SQL syntax.
optionsQueryOptionsThe 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
tableTableThe table for which the SELECT statement will be generated.
keyKeyThe key defining the filter criteria for the SELECT statement.
optionsQueryOptionsThe 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
tableTableThe table for which the SELECT statement will be generated.
optionsQueryOptionsThe 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
tableTableThe table for which the UPDATE statement will be generated.
providerNamestringThe name of the database provider being used, which determines SQL syntax specifics.
optionsQueryOptionsThe 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
tableTableThe table where the data will be inserted.
rowValuesobject[]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
tableTableThe table into which the rows will be inserted.
rowValuesIEnumerable<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
TRowThe 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
tableTableThe target table into which the rows will be inserted.
rowValuesIEnumerable<TRow>The collection of data rows to insert into the table.
rowBinderAction<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
TRowThe 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
tableTableThe table into which the row will be inserted.
rowValueTRowThe data for the row to be inserted.
Returns
- bool
A boolean indicating whether the row was successfully inserted.
Type Parameters
TRowThe 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
tableTableThe table where the row will be inserted.
rowValueTRowThe value of the row to insert.
rowBinderAction<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
TRowThe 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
tableTableThe table for which the data reader will be opened.
optionsQueryOptionsThe 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
tableTableThe 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
TRowThe 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
tableTableThe table from which to select rows.
keyKeyThe key that defines the criteria used for selection.
keyValuesobject[]The values of the key to be used as the selection criteria.
Returns
- List<TRow>
A list of entities of type
TRowrepresenting the selected rows.
Type Parameters
TRowThe 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
tableTableThe table on which the SELECT query will be executed.
extractorFunc<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
TRowSetThe 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
tableTableThe table for which the SELECT query will be executed.
keyKeyThe key used to filter the query results.
keyValueTKeyThe value of the key to use with the SELECT query.
keyBinderAction<DbCommand, TKey>A function that binds the key value to the database command parameters.
extractorFunc<DbDataReader, TRowSet>A function that extracts data from the query results and maps it to the specified type.
Returns
- TRowSet
An instance of
TRowSetcontaining the extracted query results.
Type Parameters
TRowSetThe type into which the query results will be mapped.
TKeyThe 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
tableTableThe table where the batch update will be applied.
rowValuesIEnumerable<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
TRowThe 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
tableTableThe table where the rows will be updated.
rowValuesIEnumerable<TRow>The collection of row values to update the table with.
rowBinderAction<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
TRowThe 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
tableTableThe table to be updated.
rowValueTRowThe object containing the data to update the table with.
Returns
- bool
A boolean indicating whether the update operation was successful.
Type Parameters
TRowThe 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
tableTableThe table on which the update operation will be executed.
rowValueTRowThe row data containing the values to be updated.
rowBinderAction<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
TRowThe type of the row value being updated.