' <fileinfo name="OrdersCollection_Base.vb">
' <copyright>
' All rights reserved.
' </copyright>
' <remarks>
' Do not change this source code manually. Changes to this file may
' cause incorrect behavior and will be lost if the code is regenerated.
' </remarks>
' <generator rewritefile="True" infourl="http://www.SharpPower.com">RapTier</generator>
' </fileinfo>
Option Strict Off
Option Explicit On
Imports System
Imports System.Data
''' <summary>
''' The base class for <see cref="OrdersCollection"/>. Provides methods
''' for common database table operations.
''' </summary>
''' <remarks>
''' Do not change this source code. Update the <see cref="OrdersCollection"/>
''' class if you need to add or change some functionality.
''' </remarks>
Public MustInherit Class OrdersCollection_Base
' Constants
Public Const OrderIDColumnName As String = "OrderID"
Public Const CustomerIDColumnName As String = "CustomerID"
Public Const EmployeeIDColumnName As String = "EmployeeID"
Public Const OrderDateColumnName As String = "OrderDate"
Public Const RequiredDateColumnName As String = "RequiredDate"
Public Const ShippedDateColumnName As String = "ShippedDate"
Public Const ShipViaColumnName As String = "ShipVia"
Public Const FreightColumnName As String = "Freight"
Public Const ShipNameColumnName As String = "ShipName"
Public Const ShipAddressColumnName As String = "ShipAddress"
Public Const ShipCityColumnName As String = "ShipCity"
Public Const ShipRegionColumnName As String = "ShipRegion"
Public Const ShipPostalCodeColumnName As String = "ShipPostalCode"
Public Const ShipCountryColumnName As String = "ShipCountry"
' Instance fields
Private _db As Northwind
''' <summary>
''' Initializes a new instance of the <see cref="OrdersCollection_Base"/>
''' class with the specified <see cref="Northwind"/>.
''' </summary>
''' <param name="db">The <see cref="Northwind"/> object.</param>
Public Sub New(db As Northwind)
MyBase.New()
_db = db
End Sub
''' <summary>
''' Gets the database object that this table belongs to.
''' </summary>
''' <value>The <see cref="Northwind"/> object.</value>
Protected ReadOnly Property Database As Northwind
Get
Return _db
End Get
End Property
''' <summary>
''' Gets an array of all records from the <c>Orders</c> table.
''' </summary>
''' <returns>An array of <see cref="OrdersRow"/> objects.</returns>
Public Overridable Function GetAll() As OrdersRow()
Return MapRecords(CreateGetAllCommand())
End Function
''' <summary>
''' Gets a <see cref="System.Data.DataTable"/> object that
''' includes all records from the <c>Orders</c> table.
''' </summary>
''' <returns>A reference to the <see cref="System.Data.DataTable"/> object.</returns>
Public Overridable Function GetAllAsDataTable() As DataTable
Return MapRecordsToDataTable(CreateGetAllCommand())
End Function
''' <summary>
''' Creates and returns an <see cref="System.Data.IDbCommand"/> object that is used
''' to retrieve all records from the <c>Orders</c> table.
''' </summary>
''' <returns>A reference to the <see cref="System.Data.IDbCommand"/> object.</returns>
Protected Overridable Function CreateGetAllCommand() As IDbCommand
Return CreateGetCommand(Nothing, Nothing)
End Function
''' <summary>
''' Gets the first <see cref="OrdersRow"/> objects that
''' match the search condition.
''' </summary>
''' <param name="whereSql">The SQL search condition. For example:
''' <c>"FirstName='Smith' AND Zip=75038"</c>.</param>
''' <returns>An instance of <see cref="OrdersRow"/> or null reference
''' (Nothing in Visual Basic) if the object was not found.</returns>
Public Function GetRow(whereSql As String) As OrdersRow
Dim totalRecordCount As Integer = -1
Dim rows As OrdersRow() = GetAsArray(whereSql, Nothing, 0, 1, totalRecordCount)
If 0 = rows.Length Then
Return Nothing
End If
Return rows(0)
End Function
''' <summary>
''' Gets an array of <see cref="OrdersRow"/> objects that
''' match the search condition, in the the specified sort order.
''' </summary>
''' <param name="whereSql">The SQL search condition. For example:
''' <c>"FirstName='Smith' AND Zip=75038"</c>.</param>
''' <param name="orderBySql">The column name(s) followed by "ASC" (ascending) or "DESC" (descending).
''' Columns are sorted in ascending order by default. For example: <c>"LastName ASC, FirstName ASC"</c>.</param>
''' <returns>An array of <see cref="OrdersRow"/> objects.</returns>
Public Function GetAsArray(whereSql As String, orderBySql As String) As OrdersRow()
Dim totalRecordCount As Integer = -1
Return GetAsArray(whereSql, orderBySql, 0, Integer.MaxValue, totalRecordCount)
End Function
''' <summary>
''' Gets an array of <see cref="OrdersRow"/> objects that
''' match the search condition, in the the specified sort order.
''' </summary>
''' <param name="whereSql">The SQL search condition. For example:
''' <c>"FirstName='Smith' AND Zip=75038"</c>.</param>
''' <param name="orderBySql">The column name(s) followed by "ASC" (ascending) or "DESC" (descending).
''' Columns are sorted in ascending order by default. For example: <c>"LastName ASC, FirstName ASC"</c>.</param>
''' <param name="startIndex">The index of the first record to return.</param>
''' <param name="length">The number of records to return.</param>
''' <param name="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.</param>
''' <returns>An array of <see cref="OrdersRow"/> objects.</returns>
Public Overridable Function GetAsArray(whereSql As String, orderBySql As String, _
startIndex As Integer, length As Integer, _
ByRef totalRecordCount As Integer) As OrdersRow()
Dim reader As IDataReader = _db.ExecuteReader(CreateGetCommand(whereSql, orderBySql))
Try
Return MapRecords(reader, startIndex, length, totalRecordCount)
Finally
reader.Dispose()
End Try
End Function
''' <summary>
''' Gets a <see cref="System.Data.DataTable"/> object filled with data that
''' match the search condition, in the the specified sort order.
''' </summary>
''' <param name="whereSql">The SQL search condition. For example: "FirstName='Smith' AND Zip=75038".</param>
''' <param name="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".</param>
''' <returns>A reference to the <see cref="System.Data.DataTable"/> object.</returns>
Public Function GetAsDataTable(whereSql As String, orderBySql As String) As DataTable
Dim totalRecordCount As Integer = -1
return GetAsDataTable(whereSql, orderBySql, 0, Integer.MaxValue, totalRecordCount)
End Function
''' <summary>
''' Gets a <see cref="System.Data.DataTable"/> object filled with data that
''' match the search condition, in the the specified sort order.
''' </summary>
''' <param name="whereSql">The SQL search condition. For example: "FirstName='Smith' AND Zip=75038".</param>
''' <param name="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".</param>
''' <param name="startIndex">The index of the first record to return.</param>
''' <param name="length">The number of records to return.</param>
''' <param name="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.</param>
''' <returns>A reference to the <see cref="System.Data.DataTable"/> object.</returns>
Public Overridable Function GetAsDataTable(whereSql As String, orderBySql As String, _
startIndex As Integer, length As Integer, _
ByRef totalRecordCount As Integer) As DataTable
Dim reader As IDataReader = _db.ExecuteReader(CreateGetCommand(whereSql, orderBySql))
Try
Return MapRecordsToDataTable(reader, startIndex, length, totalRecordCount)
Finally
reader.Dispose()
End Try
End Function
''' <summary>
''' Creates an <see cref="System.Data.IDbCommand"/> object for the specified search criteria.
''' </summary>
''' <param name="whereSql">The SQL search condition. For example: "FirstName='Smith' AND Zip=75038".</param>
''' <param name="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".</param>
''' <returns>A reference to the <see cref="System.Data.IDbCommand"/> object.</returns>
Protected Overridable Function CreateGetCommand(whereSql As String, _
orderBySql As String) As IDbCommand
Dim sql As String = "SELECT * FROM [dbo].[Orders]"
If Not(whereSql Is Nothing) AndAlso 0 < whereSql.Length Then
sql += " WHERE " + whereSql
End If
If Not(orderBySql Is Nothing) AndAlso 0 < orderBySql.Length Then
sql += " ORDER BY " + orderBySql
End If
Return _db.CreateCommand(sql)
End Function
''' <summary>
''' Gets <see cref="OrdersRow"/> by the primary key.
''' </summary>
''' <param name="orderID">The <c>OrderID</c> column value.</param>
''' <returns>An instance of <see cref="OrdersRow"/> or null reference
''' (Nothing in Visual Basic) if the object was not found.</returns>
Public Overridable Function GetByPrimaryKey(orderID As Integer) As OrdersRow
Dim whereSql As String = "[OrderID]=" + _db.CreateSqlParameterName("OrderID")
Dim cmd As IDbCommand = CreateGetCommand(whereSql, Nothing)
AddParameter(cmd, "OrderID", orderID)
Dim tempArray As OrdersRow() = MapRecords(cmd)
If 0 = tempArray.Length Then
Return Nothing
End If
Return tempArray(0)
End Function
''' <summary>
''' Gets an array of <see cref="OrdersRow"/> objects
''' by the <c>FK_Orders_Customers</c> foreign key.
''' </summary>
''' <param name="customerID">The <c>CustomerID</c> column value.</param>
''' <returns>An array of <see cref="OrdersRow"/> objects.</returns>
Public Overridable Function GetByCustomerID(customerID As String) As OrdersRow()
Return MapRecords(CreateGetByCustomerIDCommand(customerID))
End Function
''' <summary>
''' Gets a <see cref="System.Data.DataTable"/> object
''' by the <c>FK_Orders_Customers</c> foreign key.
''' </summary>
''' <param name="customerID">The <c>CustomerID</c> column value.</param>
''' <returns>A reference to the <see cref="System.Data.DataTable"/> object.</returns>
Public Overridable Function GetByCustomerIDAsDataTable(customerID As String) As DataTable
Return MapRecordsToDataTable(CreateGetByCustomerIDCommand(customerID))
End Function
''' <summary>
''' Creates an <see cref="System.Data.IDbCommand"/> object that can be used to
''' return records by the <c>FK_Orders_Customers</c> foreign key.
''' </summary>
''' <param name="customerID">The <c>CustomerID</c> column value.</param>
''' <returns>A reference to the <see cref="System.Data.IDbCommand"/> object.</returns>
Protected Overridable Function CreateGetByCustomerIDCommand( _
customerID As String) As IDbCommand
Dim whereSql As String = ""
If customerID Is Nothing Then
whereSql += "[CustomerID] IS NULL"
Else
whereSql += "[CustomerID]=" + _db.CreateSqlParameterName("CustomerID")
End If
Dim cmd As IDbCommand = CreateGetCommand(whereSql, Nothing)
If Not(customerID Is Nothing) Then
AddParameter(cmd, "CustomerID", customerID)
End If
Return cmd
End Function
''' <summary>
''' Gets an array of <see cref="OrdersRow"/> objects
''' by the <c>FK_Orders_Employees</c> foreign key.
''' </summary>
''' <param name="employeeID">The <c>EmployeeID</c> column value.</param>
''' <returns>An array of <see cref="OrdersRow"/> objects.</returns>
Public Function GetByEmployeeID(employeeID As Integer) As OrdersRow()
Return GetByEmployeeID(employeeID, False)
End Function
''' <summary>
''' Gets an array of <see cref="OrdersRow"/> objects
''' by the <c>FK_Orders_Employees</c> foreign key.
''' </summary>
''' <param name="employeeID">The <c>EmployeeID</c> column value.</param>
''' <param name="employeeIDNull">true if the method ignores the employeeID
''' parameter value and uses DbNull instead of it; otherwise, false.</param>
''' <returns>An array of <see cref="OrdersRow"/> objects.</returns>
Public Overridable Function GetByEmployeeID(employeeID As Integer, employeeIDNull As Boolean) As OrdersRow()
Return MapRecords(CreateGetByEmployeeIDCommand(employeeID, employeeIDNull))
End Function
''' <summary>
''' Gets a <see cref="System.Data.DataTable"/> object
''' by the <c>FK_Orders_Employees</c> foreign key.
''' </summary>
''' <param name="employeeID">The <c>EmployeeID</c> column value.</param>
''' <returns>A reference to the <see cref="System.Data.DataTable"/> object.</returns>
Public Function GetByEmployeeIDAsDataTable(employeeID As Integer) As DataTable
Return GetByEmployeeIDAsDataTable(employeeID, False)
End Function
''' <summary>
''' Gets a <see cref="System.Data.DataTable"/> object
''' by the <c>FK_Orders_Employees</c> foreign key.
''' </summary>
''' <param name="employeeID">The <c>EmployeeID</c> column value.</param>
''' <param name="employeeIDNull">true if the method ignores the employeeID
''' parameter value and uses DbNull instead of it; otherwise, false.</param>
''' <returns>A reference to the <see cref="System.Data.DataTable"/> object.</returns>
Public Overridable Function GetByEmployeeIDAsDataTable(employeeID As Integer, employeeIDNull As Boolean) As DataTable
Return MapRecordsToDataTable(CreateGetByEmployeeIDCommand(employeeID, employeeIDNull))
End Function
''' <summary>
''' Creates an <see cref="System.Data.IDbCommand"/> object that can be used to
''' return records by the <c>FK_Orders_Employees</c> foreign key.
''' </summary>
''' <param name="employeeID">The <c>EmployeeID</c> column value.</param>
''' <param name="employeeIDNull">true if the method ignores the employeeID
''' parameter value and uses DbNull instead of it; otherwise, false.</param>
''' <returns>A reference to the <see cref="System.Data.IDbCommand"/> object.</returns>
Protected Overridable Function CreateGetByEmployeeIDCommand( _
employeeID As Integer, employeeIDNull As Boolean) As IDbCommand
Dim whereSql As String = ""
If employeeIDNull Then
whereSql += "[EmployeeID] IS NULL"
Else
whereSql += "[EmployeeID]=" + _db.CreateSqlParameterName("EmployeeID")
End If
Dim cmd As IDbCommand = CreateGetCommand(whereSql, Nothing)
If Not employeeIDNull Then
AddParameter(cmd, "EmployeeID", employeeID)
End If
Return cmd
End Function
''' <summary>
''' Gets an array of <see cref="OrdersRow"/> objects
''' by the <c>FK_Orders_Shippers</c> foreign key.
''' </summary>
''' <param name="shipVia">The <c>ShipVia</c> column value.</param>
''' <returns>An array of <see cref="OrdersRow"/> objects.</returns>
Public Function GetByShipVia(shipVia As Integer) As OrdersRow()
Return GetByShipVia(shipVia, False)
End Function
''' <summary>
''' Gets an array of <see cref="OrdersRow"/> objects
''' by the <c>FK_Orders_Shippers</c> foreign key.
''' </summary>
''' <param name="shipVia">The <c>ShipVia</c> column value.</param>
''' <param name="shipViaNull">true if the method ignores the shipVia
''' parameter value and uses DbNull instead of it; otherwise, false.</param>
''' <returns>An array of <see cref="OrdersRow"/> objects.</returns>
Public Overridable Function GetByShipVia(shipVia As Integer, shipViaNull As Boolean) As OrdersRow()
Return MapRecords(CreateGetByShipViaCommand(shipVia, shipViaNull))
End Function
''' <summary>
''' Gets a <see cref="System.Data.DataTable"/> object
''' by the <c>FK_Orders_Shippers</c> foreign key.
''' </summary>
''' <param name="shipVia">The <c>ShipVia</c> column value.</param>
''' <returns>A reference to the <see cref="System.Data.DataTable"/> object.</returns>
Public Function GetByShipViaAsDataTable(shipVia As Integer) As DataTable
Return GetByShipViaAsDataTable(shipVia, False)
End Function
''' <summary>
''' Gets a <see cref="System.Data.DataTable"/> object
''' by the <c>FK_Orders_Shippers</c> foreign key.
''' </summary>
''' <param name="shipVia">The <c>ShipVia</c> column value.</param>
''' <param name="shipViaNull">true if the method ignores the shipVia
''' parameter value and uses DbNull instead of it; otherwise, false.</param>
''' <returns>A reference to the <see cref="System.Data.DataTable"/> object.</returns>
Public Overridable Function GetByShipViaAsDataTable(shipVia As Integer, shipViaNull As Boolean) As DataTable
Return MapRecordsToDataTable(CreateGetByShipViaCommand(shipVia, shipViaNull))
End Function
''' <summary>
''' Creates an <see cref="System.Data.IDbCommand"/> object that can be used to
''' return records by the <c>FK_Orders_Shippers</c> foreign key.
''' </summary>
''' <param name="shipVia">The <c>ShipVia</c> column value.</param>
''' <param name="shipViaNull">true if the method ignores the shipVia
''' parameter value and uses DbNull instead of it; otherwise, false.</param>
''' <returns>A reference to the <see cref="System.Data.IDbCommand"/> object.</returns>
Protected Overridable Function CreateGetByShipViaCommand( _
shipVia As Integer, shipViaNull As Boolean) As IDbCommand
Dim whereSql As String = ""
If shipViaNull Then
whereSql += "[ShipVia] IS NULL"
Else
whereSql += "[ShipVia]=" + _db.CreateSqlParameterName("ShipVia")
End If
Dim cmd As IDbCommand = CreateGetCommand(whereSql, Nothing)
If Not shipViaNull Then
AddParameter(cmd, "ShipVia", shipVia)
End If
Return cmd
End Function
''' <summary>
''' Adds a new record into the <c>Orders</c> table.
''' </summary>
''' <param name="value">The <see cref="OrdersRow"/> object to be inserted.</param>
Public Overridable Sub Insert(value As OrdersRow)
Dim sqlStr As String = "INSERT INTO [dbo].[Orders] (" + _
"[CustomerID], " + _
"[EmployeeID], " + _
"[OrderDate], " + _
"[RequiredDate], " + _
"[ShippedDate], " + _
"[ShipVia], " + _
"[Freight], " + _
"[ShipName], " + _
"[ShipAddress], " + _
"[ShipCity], " + _
"[ShipRegion], " + _
"[ShipPostalCode], " + _
"[ShipCountry]" + _
") VALUES (" + _
_db.CreateSqlParameterName("CustomerID") + ", " + _
_db.CreateSqlParameterName("EmployeeID") + ", " + _
_db.CreateSqlParameterName("OrderDate") + ", " + _
_db.CreateSqlParameterName("RequiredDate") + ", " + _
_db.CreateSqlParameterName("ShippedDate") + ", " + _
_db.CreateSqlParameterName("ShipVia") + ", " + _
_db.CreateSqlParameterName("Freight") + ", " + _
_db.CreateSqlParameterName("ShipName") + ", " + _
_db.CreateSqlParameterName("ShipAddress") + ", " + _
_db.CreateSqlParameterName("ShipCity") + ", " + _
_db.CreateSqlParameterName("ShipRegion") + ", " + _
_db.CreateSqlParameterName("ShipPostalCode") + ", " + _
_db.CreateSqlParameterName("ShipCountry") + ");SELECT @@IDENTITY"
Dim cmd As IDbCommand = _db.CreateCommand(sqlStr)
AddParameter(cmd, "CustomerID", value.CustomerID)
If value.IsEmployeeIDNull Then
AddParameter(cmd, "EmployeeID", DBNull.Value)
Else
AddParameter(cmd, "EmployeeID", value.EmployeeID)
End If
If value.IsOrderDateNull Then
AddParameter(cmd, "OrderDate", DBNull.Value)
Else
AddParameter(cmd, "OrderDate", value.OrderDate)
End If
If value.IsRequiredDateNull Then
AddParameter(cmd, "RequiredDate", DBNull.Value)
Else
AddParameter(cmd, "RequiredDate", value.RequiredDate)
End If
If value.IsShippedDateNull Then
AddParameter(cmd, "ShippedDate", DBNull.Value)
Else
AddParameter(cmd, "ShippedDate", value.ShippedDate)
End If
If value.IsShipViaNull Then
AddParameter(cmd, "ShipVia", DBNull.Value)
Else
AddParameter(cmd, "ShipVia", value.ShipVia)
End If
If value.IsFreightNull Then
AddParameter(cmd, "Freight", DBNull.Value)
Else
AddParameter(cmd, "Freight", value.Freight)
End If
AddParameter(cmd, "ShipName", value.ShipName)
AddParameter(cmd, "ShipAddress", value.ShipAddress)
AddParameter(cmd, "ShipCity", value.ShipCity)
AddParameter(cmd, "ShipRegion", value.ShipRegion)
AddParameter(cmd, "ShipPostalCode", value.ShipPostalCode)
AddParameter(cmd, "ShipCountry", value.ShipCountry)
value.OrderID = Convert.ToInt32(cmd.ExecuteScalar())
End Sub
''' <summary>
''' Updates a record in the <c>Orders</c> table.
''' </summary>
''' <param name="value">The <see cref="OrdersRow"/>
''' object used to update the table record.</param>
''' <returns>true if the record was updated; otherwise, false.</returns>
Public Overridable Function Update(value As OrdersRow) As Boolean
Dim sqlStr As String = "UPDATE [dbo].[Orders] SET " + _
"[CustomerID]=" + _db.CreateSqlParameterName("CustomerID") + ", " + _
"[EmployeeID]=" + _db.CreateSqlParameterName("EmployeeID") + ", " + _
"[OrderDate]=" + _db.CreateSqlParameterName("OrderDate") + ", " + _
"[RequiredDate]=" + _db.CreateSqlParameterName("RequiredDate") + ", " + _
"[ShippedDate]=" + _db.CreateSqlParameterName("ShippedDate") + ", " + _
"[ShipVia]=" + _db.CreateSqlParameterName("ShipVia") + ", " + _
"[Freight]=" + _db.CreateSqlParameterName("Freight") + ", " + _
"[ShipName]=" + _db.CreateSqlParameterName("ShipName") + ", " + _
"[ShipAddress]=" + _db.CreateSqlParameterName("ShipAddress") + ", " + _
"[ShipCity]=" + _db.CreateSqlParameterName("ShipCity") + ", " + _
"[ShipRegion]=" + _db.CreateSqlParameterName("ShipRegion") + ", " + _
"[ShipPostalCode]=" + _db.CreateSqlParameterName("ShipPostalCode") + ", " + _
"[ShipCountry]=" + _db.CreateSqlParameterName("ShipCountry") + _
" WHERE " + _
"[OrderID]=" + _db.CreateSqlParameterName("OrderID")
Dim cmd As IDbCommand = _db.CreateCommand(sqlStr)
AddParameter(cmd, "CustomerID", value.CustomerID)
If value.IsEmployeeIDNull Then
AddParameter(cmd, "EmployeeID", DBNull.Value)
Else
AddParameter(cmd, "EmployeeID", value.EmployeeID)
End If
If value.IsOrderDateNull Then
AddParameter(cmd, "OrderDate", DBNull.Value)
Else
AddParameter(cmd, "OrderDate", value.OrderDate)
End If
If value.IsRequiredDateNull Then
AddParameter(cmd, "RequiredDate", DBNull.Value)
Else
AddParameter(cmd, "RequiredDate", value.RequiredDate)
End If
If value.IsShippedDateNull Then
AddParameter(cmd, "ShippedDate", DBNull.Value)
Else
AddParameter(cmd, "ShippedDate", value.ShippedDate)
End If
If value.IsShipViaNull Then
AddParameter(cmd, "ShipVia", DBNull.Value)
Else
AddParameter(cmd, "ShipVia", value.ShipVia)
End If
If value.IsFreightNull Then
AddParameter(cmd, "Freight", DBNull.Value)
Else
AddParameter(cmd, "Freight", value.Freight)
End If
AddParameter(cmd, "ShipName", value.ShipName)
AddParameter(cmd, "ShipAddress", value.ShipAddress)
AddParameter(cmd, "ShipCity", value.ShipCity)
AddParameter(cmd, "ShipRegion", value.ShipRegion)
AddParameter(cmd, "ShipPostalCode", value.ShipPostalCode)
AddParameter(cmd, "ShipCountry", value.ShipCountry)
AddParameter(cmd, "OrderID", value.OrderID)
Return 0 <> cmd.ExecuteNonQuery()
End Function
''' <summary>
''' Updates the <c>Orders</c> table and calls the <c>AcceptChanges</c> method
''' on the changed DataRow objects.
''' </summary>
''' <param name="table">The <see cref="System.Data.DataTable"/> used to update the data source.</param>
Public Sub Update(table As DataTable)
Update(table, true)
End Sub
''' <summary>
''' Updates the <c>Orders</c> table. Pass <c>false</c> as the <c>acceptChanges</c>
''' argument when your code calls this method in an ADO.NET transaction context. Note that in
''' this case, after you call the Update method you need call either <c>AcceptChanges</c>
''' or <c>RejectChanges</c> method on the DataTable object.
''' <code>
''' MyDb db = new MyDb();
''' try
''' {
''' db.BeginTransaction();
''' db.MyCollection.Update(myDataTable, false);
''' db.CommitTransaction();
''' myDataTable.AcceptChanges();
''' }
''' catch(Exception)
''' {
''' db.RollbackTransaction();
''' myDataTable.RejectChanges();
''' }
''' </code>
''' </summary>
''' <param name="table">The <see cref="System.Data.DataTable"/> used to update the data source.</param>
''' <param name="acceptChanges">Specifies whether this method calls the <c>AcceptChanges</c>
''' method on the changed DataRow objects.</param>
Public Overridable Sub Update(table As DataTable, acceptChanges As Boolean)
Dim rows As DataRowCollection = table.Rows
Dim i As Integer
For i = rows.Count - 1 To 0 Step -1
Dim row As DataRow = rows(i)
Select row.RowState
Case DataRowState.Added
Insert(MapRow(row))
If acceptChanges Then
row.AcceptChanges()
End If
Case DataRowState.Deleted
row.RejectChanges()
Try
DeleteByPrimaryKey(CType(row("OrderID"), Integer))
Finally
row.Delete()
End Try
If acceptChanges Then
row.AcceptChanges()
End If
Case DataRowState.Modified
Update(MapRow(row))
If acceptChanges Then
row.AcceptChanges()
End If
End Select
Next
End Sub
''' <summary>
''' Deletes the specified object from the <c>Orders</c> table.
''' </summary>
''' <param name="value">The <see cref="OrdersRow"/> object to delete.</param>
''' <returns>true if the record was deleted; otherwise, false.</returns>
Public Function Delete(value As OrdersRow) As Boolean
Return DeleteByPrimaryKey(value.OrderID)
End Function
''' <summary>
''' Deletes a record from the <c>Orders</c> table using
''' the specified primary key.
''' </summary>
''' <param name="orderID">The <c>OrderID</c> column value.</param>
''' <returns>true if the record was deleted; otherwise, false.</returns>
Public Overridable Function DeleteByPrimaryKey(orderID As Integer) As Boolean
Dim whereSql As String = "[OrderID]=" + _db.CreateSqlParameterName("OrderID")
Dim cmd As IDbCommand = CreateDeleteCommand(whereSql)
AddParameter(cmd, "OrderID", orderID)
Return 0 < cmd.ExecuteNonQuery()
End Function
''' <summary>
''' Deletes records from the <c>Orders</c> table using the
''' <c>FK_Orders_Customers</c> foreign key.
''' </summary>
''' <param name="customerID">The <c>CustomerID</c> column value.</param>
''' <returns>The number of records deleted from the table.</returns>
Public Function DeleteByCustomerID(customerID As String) As Integer
Return CreateDeleteByCustomerIDCommand(customerID).ExecuteNonQuery()
End Function
''' <summary>
''' Creates an <see cref="System.Data.IDbCommand"/> object that can be used to
''' delete records using the <c>FK_Orders_Customers</c> foreign key.
''' </summary>
''' <param name="customerID">The <c>CustomerID</c> column value.</param>
''' <returns>A reference to the <see cref="System.Data.IDbCommand"/> object.</returns>
Public Overridable Function CreateDeleteByCustomerIDCommand(customerID As String) As IDbCommand
Dim whereSql As String = ""
If customerID Is Nothing Then
whereSql += "[CustomerID] IS NULL"
Else
whereSql += "[CustomerID]=" + _db.CreateSqlParameterName("CustomerID")
End If
Dim cmd As IDbCommand = CreateDeleteCommand(whereSql)
If Not(customerID Is Nothing) Then
AddParameter(cmd, "CustomerID", customerID)
End If
Return cmd
End Function
''' <summary>
''' Deletes records from the <c>Orders</c> table using the
''' <c>FK_Orders_Employees</c> foreign key.
''' </summary>
''' <param name="employeeID">The <c>EmployeeID</c> column value.</param>
''' <returns>The number of records deleted from the table.</returns>
Public Function DeleteByEmployeeID(employeeID As Integer) As Integer
Return DeleteByEmployeeID(employeeID, False)
End Function
''' <summary>
''' Deletes records from the <c>Orders</c> table using the
''' <c>FK_Orders_Employees</c> foreign key.
''' </summary>
''' <param name="employeeID">The <c>EmployeeID</c> column value.</param>
''' <param name="employeeIDNull">true if the method ignores the employeeID
''' parameter value and uses DbNull instead of it; otherwise, false.</param>
''' <returns>The number of records deleted from the table.</returns>
Public Function DeleteByEmployeeID(employeeID As Integer, employeeIDNull As Boolean) As Integer
Return CreateDeleteByEmployeeIDCommand(employeeID, employeeIDNull).ExecuteNonQuery()
End Function
''' <summary>
''' Creates an <see cref="System.Data.IDbCommand"/> object that can be used to
''' delete records using the <c>FK_Orders_Employees</c> foreign key.
''' </summary>
''' <param name="employeeID">The <c>EmployeeID</c> column value.</param>
''' <param name="employeeIDNull">true if the method ignores the employeeID
''' parameter value and uses DbNull instead of it; otherwise, false.</param>
''' <returns>A reference to the <see cref="System.Data.IDbCommand"/> object.</returns>
Public Overridable Function CreateDeleteByEmployeeIDCommand(employeeID As Integer, employeeIDNull As Boolean) As IDbCommand
Dim whereSql As String = ""
If employeeIDNull Then
whereSql += "[EmployeeID] IS NULL"
Else
whereSql += "[EmployeeID]=" + _db.CreateSqlParameterName("EmployeeID")
End If
Dim cmd As IDbCommand = CreateDeleteCommand(whereSql)
If Not employeeIDNull Then
AddParameter(cmd, "EmployeeID", employeeID)
End If
Return cmd
End Function
''' <summary>
''' Deletes records from the <c>Orders</c> table using the
''' <c>FK_Orders_Shippers</c> foreign key.
''' </summary>
''' <param name="shipVia">The <c>ShipVia</c> column value.</param>
''' <returns>The number of records deleted from the table.</returns>
Public Function DeleteByShipVia(shipVia As Integer) As Integer
Return DeleteByShipVia(shipVia, False)
End Function
''' <summary>
''' Deletes records from the <c>Orders</c> table using the
''' <c>FK_Orders_Shippers</c> foreign key.
''' </summary>
''' <param name="shipVia">The <c>ShipVia</c> column value.</param>
''' <param name="shipViaNull">true if the method ignores the shipVia
''' parameter value and uses DbNull instead of it; otherwise, false.</param>
''' <returns>The number of records deleted from the table.</returns>
Public Function DeleteByShipVia(shipVia As Integer, shipViaNull As Boolean) As Integer
Return CreateDeleteByShipViaCommand(shipVia, shipViaNull).ExecuteNonQuery()
End Function
''' <summary>
''' Creates an <see cref="System.Data.IDbCommand"/> object that can be used to
''' delete records using the <c>FK_Orders_Shippers</c> foreign key.
''' </summary>
''' <param name="shipVia">The <c>ShipVia</c> column value.</param>
''' <param name="shipViaNull">true if the method ignores the shipVia
''' parameter value and uses DbNull instead of it; otherwise, false.</param>
''' <returns>A reference to the <see cref="System.Data.IDbCommand"/> object.</returns>
Public Overridable Function CreateDeleteByShipViaCommand(shipVia As Integer, shipViaNull As Boolean) As IDbCommand
Dim whereSql As String = ""
If shipViaNull Then
whereSql += "[ShipVia] IS NULL"
Else
whereSql += "[ShipVia]=" + _db.CreateSqlParameterName("ShipVia")
End If
Dim cmd As IDbCommand = CreateDeleteCommand(whereSql)
If Not shipViaNull Then
AddParameter(cmd, "ShipVia", shipVia)
End If
Return cmd
End Function
''' <summary>
''' Deletes <c>Orders</c> records that match the specified criteria.
''' </summary>
''' <param name="whereSql">The SQL search condition.
''' For example: <c>"FirstName='Smith' AND Zip=75038"</c>.</param>
''' <returns>The number of deleted records.</returns>
Public Function Delete(whereSql As String) As Integer
Return CreateDeleteCommand(whereSql).ExecuteNonQuery()
End Function
''' <summary>
''' Creates an <see cref="System.Data.IDbCommand"/> object that can be used
''' to delete <c>Orders</c> records that match the specified criteria.
''' </summary>
''' <param name="whereSql">The SQL search condition.
''' For example: <c>"FirstName='Smith' AND Zip=75038"</c>.</param>
''' <returns>A reference to the <see cref="System.Data.IDbCommand"/> object.</returns>
Protected Overridable Function CreateDeleteCommand(whereSql As String) As IDbCommand
Dim sql As String = "DELETE FROM [dbo].[Orders]"
If Not(whereSql Is Nothing) AndAlso 0 < whereSql.Length Then
sql += " WHERE " + whereSql
End If
Return _db.CreateCommand(sql)
End Function
''' <summary>
''' Deletes all records from the <c>Orders</c> table.
''' </summary>
''' <returns>The number of deleted records.</returns>
Public Function DeleteAll() As Integer
Return Delete("")
End Function
''' <summary>
''' Reads data using the specified command and returns
''' an array of mapped objects.
''' </summary>
''' <param name="command">The <see cref="System.Data.IDbCommand"/> object.</param>
''' <returns>An array of <see cref="OrdersRow"/> objects.</returns>
Protected Function MapRecords(command As IDbCommand) As OrdersRow()