<TableCodeName>Collection_Base class

A Table Data Gateway for a table or view. Provides methods to get, insert, update, and delete data in the table. This class is abstract.

Do not change this file manually. Modify the <TableCodeName>Collection class if you need to add or change some functionality.

Constructors


C#:
public <TableCodeName>Collection_Base(
      <DatabaseCodeName> db
);

VB.NET:
Public Sub New( _
      db As <DatabaseCodeName> _
)

Description

Initializes a new instance of the <TableCodeName>Collection_Base class.

Parameters

db

The object.

Properties


C#:
protected <DatabaseCodeName> Database {get;}

VB.NET:
Protected ReadOnly Property Database As <DatabaseCodeName>

Description

Gets the database object that this table belongs to.

Methods


C#:
protected virtual System.Data.IDbDataParameter AddParameter(
      System.Data.IDbCommand cmd,
      string paramName,
      object value
);

VB.NET:
Protected Overridable Function AddParameter( _
      cmd As System.Data.IDbCommand, _
      paramName As String, _
      value As Object _
) As System.Data.IDbDataParameter

Description

Adds a new parameter to the specified command.

Parameters

cmd

The object to add the parameter to.

paramName

The name of the parameter.

value

The value of the parameter.

Returns

A reference to the added parameter.

C#:
protected virtual System.Data.DataTable CreateDataTable();

VB.NET:
Protected Overridable Function CreateDataTable() As System.Data.DataTable

Description

Creates a System.Data.DataTable object.

Parameters

None

Returns

A reference to the System.Data.DataTable object.

C#:
protected virtual System.Data.IDbCommand CreateDeleteBy<ForeignKeyColumnName>Command(
       <ForeignKeyType> <foreignKeyColumnName>,
      bool <foreignKeyColumnName>Null
);

VB.NET:
Protected Overridable Function CreateDeleteBy<ForeignKeyColumnName>Command( _
      <foreignKeyColumnName> As <ForeignKeyType>, _
      <foreignKeyColumnName>Null As Boolean _
) As System.Data.IDbCommand

Description

Creates an System.Data.IDbCommand object that can be used to delete records using a foreign key value.

Parameters

foreignKeyColumnName

The foreign key value.

foreignKeyColumnNameNull

true if the method ignores the <foreignKeyColumnName> parameter value and uses DbNull instead of it; otherwise, false.

Returns

A reference to the System.Data.IDbCommand object.

C#:
protected virtual System.Data.IDbCommand CreateDeleteCommand(
      string whereSql
);

VB.NET:
Protected Overridable Function CreateDeleteCommand( _
      whereSql As String _
) As System.Data.IDbCommand

Description

Creates an System.Data.IDbCommand object that can be used to delete records that match the specified criteria.

Parameters

whereSql

The SQL search condition. For example: "FirstName='Smith' AND Zip=75038".

Returns

A reference to the System.Data.IDbCommand object.

C#:
protected virtual System.Data.IDbCommand CreateGetAllCommand();

VB.NET:
Protected Overridable Function CreateGetAllCommand() As System.Data.IDbCommand

Description

Creates and returns an System.Data.IDbCommand object that is used to retrieve all records from the table.

Parameters

None

Returns

A reference to the System.Data.IDbCommand object.

C#:
protected virtual System.Data.IDbCommand CreateGetBy<ForeignKeyColumnName>Command(
       <ForeignKeyType> <foreignKey>,
      bool <foreignKey>Null
);

VB.NET:
Protected Overridable Function CreateGetBy<ForeignKeyColumnName>Command( _
      <foreignKeyColumnName> As <ForeignKeyType>, _
      <foreignKeyColumnName>Null As Boolean _
) As System.Data.IDbCommand

Description

Creates an System.Data.IDbCommand object that can be used to return records by a foreign key.

Parameters

foreignKeyColumnName

The foreign key value.

foreignKeyColumnNameNull

true if the method ignores the <foreignKeyColumnName> parameter value and uses DbNull instead of it; otherwise, false.

Returns

A reference to the System.Data.IDbCommand object.

C#:
protected virtual System.Data.IDbCommand CreateGetCommand(
      string whereSql,
      string orderBySql
);

VB.NET:
Protected Overridable Function CreateGetCommand( _
      whereSql As String, _
      orderBySql As String _
) As System.Data.IDbCommand

Description

Creates an System.Data.IDbCommand object for the specified search criteria.

Parameters

whereSql

The SQL search condition. For example: "FirstName='Smith' AND Zip=75038".

orderBySql

The column name(s) followed by "ASC" (ascending) or "DESC" (descending). Columns are sorted in ascending order by default. For example: "LastName ASC, FirstName ASC".

Returns

A reference to the System.Data.IDbCommand object.

C#:
public bool Delete(
      <TableCodeName>Row value
);

VB.NET:
Public Function Delete( _
      value As <TableCodeName>Row _
) As Boolean

Description

Deletes the specified object from the table.

Parameters

value

The object to delete.

Returns

true if the record was deleted; otherwise, false.

C#:
public int Delete(
      string whereSql
);

VB.NET:
Public Function Delete( _
      whereSql As String _
) As Integer

Description

Deletes records that match the specified criteria.

Parameters

whereSql

The SQL search condition. For example: "FirstName='Smith' AND Zip=75038".

Returns

The number of deleted records.

C#:
public int DeleteAll();

VB.NET:
Public Function DeleteAll() As Integer

Description

Deletes all records from the table.

Parameters

None

Returns

The number of deleted records.

C#:
public int DeleteBy<ForeignKeyColumnName>(
       <ForeignKeyType> <foreignKeyColumnName>
);

VB.NET:
Public Function DeleteBy<ForeignKeyColumnName>( _
      <foreignKeyColumnName> As  <ForeignKeyType> _
) As Integer

Description

Deletes records from the table using a foreign key.

Parameters

foreignKeyColumnName

The foreign key value.

Returns

The number of records deleted from the table.

C#:
public int DeleteBy<ForeignKeyColumnName>(
       <ForeignKeyType> <foreignKeyColumnName>,
      bool <foreignKeyColumnName>Null
);

VB.NET:
Public Function DeleteBy<ForeignKeyColumnName>( _
      <foreignKeyColumnName> As <ForeignKeyType>, _
      <foreignKeyColumnName>Null As Boolean _
) As Integer

Description

Deletes records from the table using a foreign key.

Parameters

foreignKeyColumnName

The foreign key value.

foreignKeyColumnNameNull

true if the method ignores the <foreignKeyColumnName> parameter value and uses DbNull instead of it; otherwise, false.

Returns

The number of records deleted from the table.

C#:
public virtual bool DeleteByPrimaryKey(
       <PrimaryKeyType> <primaryKeyColumnName>
);

VB.NET:
Public Overridable Function DeleteByPrimaryKey( _
      < primaryKeyColumnName> As  <PrimaryKeyType> _
) As Boolean

Description

Deletes a record from the table using the specified primary key value.

Parameters

primaryKeyColumnName

The primary key value.

Returns

true if the record was deleted; otherwise, false.

C#:
public virtual <TableCodeName>Row[] GetAll();

VB.NET:
Public Overridable Function GetAll() As <TableCodeName>Row()

Description

Gets an array of all records from the table.

Parameters

None

Returns

An array of <TableCodeName>Row objects.

C#:
public virtual System.Data.DataTable GetAllAsDataTable();

VB.NET:
Public Overridable Function GetAllAsDataTable() As System.Data.DataTable

Description

Gets a System.Data.DataTable object that includes all records from the table.

Parameters

None

Returns

A reference to the System.Data.DataTable object.

C#:
public <TableCodeName>Row[] GetAsArray(
      string whereSql,
      string orderBySql
);

VB.NET:
Public Function GetAsArray( _
      whereSql As String, _
      orderBySql As String _
) As <TableCodeName>Row()

Description

Gets an array of <TableCodeName>Row objects that match the search condition, in the the specified sort order.

Parameters

whereSql

The SQL search condition. For example: "FirstName='Smith' AND Zip=75038".

orderBySql

The column name(s) followed by "ASC" (ascending) or "DESC" (descending). Columns are sorted in ascending order by default. For example: "LastName ASC, FirstName ASC".

Returns

An array of <TableCodeName>Row objects.

C#:
public virtual <TableCodeName>Row[] GetAsArray(
      string whereSql,
      string orderBySql,
      int startIndex,
      int length,
      int totalRecordCount
);

VB.NET:
Public Overridable Function GetAsArray( _
      whereSql As String, _
      orderBySql As String, _
      startIndex As Integer, _
      length As Integer, _
      totalRecordCount As Integer _
) As <TableCodeName>Row()

Description

Gets an array of <TableCodeName>Row objects that match the search condition, in the the specified sort order.

Parameters

whereSql

The SQL search condition. For example: "FirstName='Smith' AND Zip=75038".

orderBySql

The column name(s) followed by "ASC" (ascending) or "DESC" (descending). Columns are sorted in ascending order by default. For example: "LastName ASC, FirstName ASC".

startIndex

The index of the first record to return.

length

The number of records to return.

totalRecordCount

A reference parameter that returns the total number of records in the reader object if 0 was passed into the method; otherwise it returns -1.

Returns

An array of <TableCodeName>Row objects.

C#:
public System.Data.DataTable GetAsDataTable(
      string whereSql,
      string orderBySql
);

VB.NET:
Public Function GetAsDataTable( _
      whereSql As String, _
      orderBySql As String _
) As System.Data.DataTable

Description

Gets a System.Data.DataTable object filled with data that match the search condition, in the the specified sort order.

Parameters

whereSql

The SQL search condition. For example: "FirstName='Smith' AND Zip=75038".

orderBySql

The column name(s) followed by "ASC" (ascending) or "DESC" (descending). Columns are sorted in ascending order by default. For example: "LastName ASC, FirstName ASC".

Returns

A reference to the System.Data.DataTable object.

C#:
public virtual System.Data.DataTable GetAsDataTable(
      string whereSql,
      string orderBySql,
      int startIndex,
      int length,
      int totalRecordCount
);

VB.NET:
Public Overridable Function GetAsDataTable( _
      whereSql As String, _
      orderBySql As String, _
      startIndex As Integer, _
      length As Integer, _
      totalRecordCount As Integer _
) As System.Data.DataTable

Description

Gets a System.Data.DataTable object filled with data that match the search condition, in the the specified sort order.

Parameters

whereSql

The SQL search condition. For example: "FirstName='Smith' AND Zip=75038".

orderBySql

The column name(s) followed by "ASC" (ascending) or "DESC" (descending). Columns are sorted in ascending order by default. For example: "LastName ASC, FirstName ASC".

startIndex

The index of the first record to return.

length

The number of records to return.

totalRecordCount

A reference parameter that returns the total number of records in the reader object if 0 was passed into the method; otherwise it returns -1.

Returns

A reference to the System.Data.DataTable object.

C#:
public <TableCodeName>Row[] GetBy<ForeignKeyColumnName>(
       <ForeignKeyType> <foreignKeyColumnName>
);

VB.NET:
Public Function GetBy<ForeignKeyColumnName>( _
      <foreignKeyColumnName> As  <ForeignKeyType> _
) As <TableCodeName>Row()

Description

Gets an array of <TableCodeName>Row objects by a foreign key.

Parameters

foreignKeyColumnName

The foreign key value.

Returns

An array of <TableCodeName>Row objects.

C#:
public virtual <TableCodeName>Row[] GetBy<ForeignKeyColumnName>(
       <ForeignKeyType> <foreignKeyColumnName>,
      bool <foreignKeyColumnName>Null
);

VB.NET:
Public Overridable Function GetBy<ForeignKeyColumnName>( _
      <foreignKeyColumnName> As <ForeignKeyType>, _
      <foreignKeyColumnName>Null As Boolean _
) As <TableCodeName>Row()

Description

Gets an array of <TableCodeName>Row objects by a foreign key.

Parameters

foreignKeyColumnName

The foreign key value.

foreignKeyColumnNameNull

true if the method ignores the <foreignKeyColumnName> parameter value and uses DbNull instead of it; otherwise, false.

Returns

An array of <TableCodeName>Row objects.

C#:
public System.Data.DataTable GetBy<ForeignKeyColumnName>AsDataTable(
       <ForeignKeyType> <foreignKeyColumnName>
);

VB.NET:
Public Function GetBy<ForeignKeyColumnName>AsDataTable( _
      <foreignKeyColumnName> As  <ForeignKeyType> _
) As System.Data.DataTable

Description

Gets a System.Data.DataTable object by a foreign key.

Parameters

foreignKeyColumnName

The foreign key value.

Returns

A reference to the System.Data.DataTable object.

C#:
public virtual System.Data.DataTable GetBy<ForeignKeyColumnName>AsDataTable(
       <ForeignKeyType> <foreignKeyColumnName>,
      bool <foreignKeyColumnName>Null
);

VB.NET:
Public Overridable Function GetByForeignKeyAsDataTable( _
      <foreignKeyColumnName> As <ForeignKeyType>, _
      <foreignKeyColumnName>Null As Boolean _
) As System.Data.DataTable

Description

Gets a System.Data.DataTable object by a foreign key.

Parameters

foreignKeyColumnName

The foreign key value.

foreignKeyColumnNameNull

true if the method ignores the <foreignKeyColumnName> parameter value and uses DbNull instead of it; otherwise, false.

Returns

A reference to the System.Data.DataTable object.

C#:
public virtual <TableCodeName>Row GetByPrimaryKey(
       <PrimaryKeyType> <primaryKeyColumnName>
);

VB.NET:
Public Overridable Function GetByPrimaryKey( _
      <primaryKeyColumnName> As  <PrimaryKeyType> _
) As <TableCodeName>Row

Description

Gets <TableCodeName>Row by the primary key.

Parameters

primaryKeyColumnName

The primary key value.

Returns

An instance of <TableCodeName>Row or null reference (Nothing in Visual Basic) if the object was not found.

C#:
public virtual void Insert(
      <TableCodeName>Row value
);

VB.NET:
Public Overridable Sub Insert( _
      value As <TableCodeName>Row _
)

Description

Adds a new record into the table.

Parameters

value

The object to be inserted.

C#:
protected <TableCodeName>Row[] MapRecords(
      System.Data.IDataReader reader
);

VB.NET:
Protected Function MapRecords( _
      reader As System.Data.IDataReader _
) As <TableCodeName>Row()

Description

Reads data from the provided data reader and returns an array of mapped objects.

Parameters

reader

The object to read data from the table.

Returns

An array of <TableCodeName>Row objects.

C#:
protected virtual <TableCodeName>Row[] MapRecords(
      System.Data.IDataReader reader,
      int startIndex,
      int length,
      int totalRecordCount
);

VB.NET:
Protected Overridable Function MapRecords( _
      reader As System.Data.IDataReader, _
      startIndex As Integer, _
      length As Integer, _
      totalRecordCount As Integer _
) As <TableCodeName>Row()

Description

Reads data from the provided data reader and returns an array of mapped objects.

Parameters

reader

The object to read data from the table.

startIndex

The index of the first record to map.

length

The number of records to map.

totalRecordCount

A reference parameter that returns the total number of records in the reader object if 0 was passed into the method; otherwise it returns -1.

Returns

An array of <TableCodeName>Row objects.

C#:
protected System.Data.DataTable MapRecordsToDataTable(
      System.Data.IDataReader reader
);

VB.NET:
Protected Function MapRecordsToDataTable( _
      reader As System.Data.IDataReader _
) As System.Data.DataTable

Description

Reads data from the provided data reader and returns a filled System.Data.DataTable object.

Parameters

reader

The object to read data from the table.

Returns

A reference to the System.Data.DataTable object.

C#:
protected virtual System.Data.DataTable MapRecordsToDataTable(
      System.Data.IDataReader reader,
      int startIndex,
      int length,
      int totalRecordCount
);

VB.NET:
Protected Overridable Function MapRecordsToDataTable( _
      reader As System.Data.IDataReader, _
      startIndex As Integer, _
      length As Integer, _
      totalRecordCount As Integer _
) As System.Data.DataTable

Description

Reads data from the provided data reader and returns a filled System.Data.DataTable object.

Parameters

reader

The object to read data from the table.

startIndex

The index of the first record to read.

length

The number of records to read.

totalRecordCount

A reference parameter that returns the total number of records in the reader object if 0 was passed into the method; otherwise it returns -1.

Returns

A reference to the System.Data.DataTable object.

C#:
protected virtual <TableCodeName>Row MapRow(
      System.Data.DataRow row
);

VB.NET:
Protected Overridable Function MapRow( _
      row As System.Data.DataRow _
) As <TableCodeName>Row

Description

Converts System.Data.DataRow to <TableCodeName>Row.

Parameters

row

The object to be mapped.

Returns

A reference to the <TableCodeName>Row object.

C#:
public virtual bool Update(
      <TableCodeName>Row value
);

VB.NET:
Public Overridable Function Update( _
      value As <TableCodeName>Row _
) As Boolean

Description

Updates a record in the table.

Parameters

value

The object used to update the table record.

Returns

true if the record was updated; otherwise, false.

C#:
public virtual void Update(
      System.Data.DataTable table
);

VB.NET:
Public Overridable Sub Update( _
      table As System.Data.DataTable _
)

Description

Updates the table.

Parameters

table

The used to update the data source.