' <fileinfo name="OrdersQryCollection_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="OrdersQryCollection"/>. Provides methods 
''' for common database view operations. 
''' </summary>
''' <remarks>
''' Do not change this source code. Update the <see cref="OrdersQryCollection"/>
''' class if you need to add or change some functionality.
''' </remarks>
Public MustInherit Class OrdersQryCollection_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"
    Public Const CompanyNameColumnName As String = "CompanyName"
    Public Const AddressColumnName As String = "Address"
    Public Const CityColumnName As String = "City"
    Public Const RegionColumnName As String = "Region"
    Public Const PostalCodeColumnName As String = "PostalCode"
    Public Const CountryColumnName As String = "Country"

    ' Instance fields
    Private _db As Northwind

    ''' <summary>
    ''' Initializes a new instance of the <see cref="OrdersQryCollection_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 view 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 Qry</c> view.
    ''' </summary>
    ''' <returns>An array of <see cref="OrdersQryRow"/> objects.</returns>
    Public Overridable Function GetAll() As OrdersQryRow()
        Return MapRecords(CreateGetAllCommand())
    End Function

    ''' <summary>
    ''' Gets a <see cref="System.Data.DataTable"/> object that 
    ''' includes all records from the <c>Orders Qry</c> view.
    ''' </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 Qry</c> view.
    ''' </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="OrdersQryRow"/> 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="OrdersQryRow"/> or null reference 
    ''' (Nothing in Visual Basic) if the object was not found.</returns>
    Public Function GetRow(whereSql As String) As OrdersQryRow
        Dim totalRecordCount As Integer = -1
        Dim rows As OrdersQryRow() = 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="OrdersQryRow"/> 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="OrdersQryRow"/> objects.</returns>
    Public Function GetAsArray(whereSql As String, orderBySql As String) As OrdersQryRow()
        Dim totalRecordCount As Integer = -1
        Return GetAsArray(whereSql, orderBySql, 0, Integer.MaxValue, totalRecordCount)
    End Function

    ''' <summary>
    ''' Gets an array of <see cref="OrdersQryRow"/> 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="OrdersQryRow"/> objects.</returns>
    Public Overridable Function GetAsArray(whereSql As String, orderBySql As String, _
                        startIndex As Integer, length As Integer, _
                        ByRef totalRecordCount As Integer) As OrdersQryRow()
        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 Qry]"
        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>
    ''' 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="OrdersQryRow"/> objects.</returns>
    Protected Function MapRecords(command As IDbCommand) As OrdersQryRow()
        Dim reader As IDataReader = _db.ExecuteReader(command)
        Try
            Return MapRecords(reader)
        Finally
            reader.Dispose()
        End Try
    End Function

    ''' <summary>
    ''' Reads data from the provided data reader and returns 
    ''' an array of mapped objects.
    ''' </summary>
    ''' <param name="reader">The <see cref="System.Data.IDataReader"/> object to read data from the view.</param>
    ''' <returns>An array of <see cref="OrdersQryRow"/> objects.</returns>
    Protected Function MapRecords(reader As IDataReader) As OrdersQryRow()
        Dim totalRecordCount As Integer = -1
        Return MapRecords(reader, 0, Integer.MaxValue, totalRecordCount)
    End Function

    ''' <summary>
    ''' Reads data from the provided data reader and returns 
    ''' an array of mapped objects.
    ''' </summary>
    ''' <param name="reader">The <see cref="System.Data.IDataReader"/> object to read data from the view.</param>
    ''' <param name="startIndex">The index of the first record to map.</param>
    ''' <param name="length">The number of records to map.</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="OrdersQryRow"/> objects.</returns>
    Protected Overridable Function MapRecords(reader As IDataReader, startIndex As Integer, _
                        length As Integer, ByRef totalRecordCount As Integer) As OrdersQryRow()
        If 0 > startIndex Then
            Throw New ArgumentOutOfRangeException("startIndex", startIndex, "StartIndex cannot be less than zero.")
        End If
        If 0 > length Then
            Throw New ArgumentOutOfRangeException("length", length, "Length cannot be less than zero.")
        End If

        Dim orderIDColumnIndex As Integer = reader.GetOrdinal("OrderID")
        Dim customerIDColumnIndex As Integer = reader.GetOrdinal("CustomerID")
        Dim employeeIDColumnIndex As Integer = reader.GetOrdinal("EmployeeID")
        Dim orderDateColumnIndex As Integer = reader.GetOrdinal("OrderDate")
        Dim requiredDateColumnIndex As Integer = reader.GetOrdinal("RequiredDate")
        Dim shippedDateColumnIndex As Integer = reader.GetOrdinal("ShippedDate")
        Dim shipViaColumnIndex As Integer = reader.GetOrdinal("ShipVia")
        Dim freightColumnIndex As Integer = reader.GetOrdinal("Freight")
        Dim shipNameColumnIndex As Integer = reader.GetOrdinal("ShipName")
        Dim shipAddressColumnIndex As Integer = reader.GetOrdinal("ShipAddress")
        Dim shipCityColumnIndex As Integer = reader.GetOrdinal("ShipCity")
        Dim shipRegionColumnIndex As Integer = reader.GetOrdinal("ShipRegion")
        Dim shipPostalCodeColumnIndex As Integer = reader.GetOrdinal("ShipPostalCode")
        Dim shipCountryColumnIndex As Integer = reader.GetOrdinal("ShipCountry")
        Dim companyNameColumnIndex As Integer = reader.GetOrdinal("CompanyName")
        Dim addressColumnIndex As Integer = reader.GetOrdinal("Address")
        Dim cityColumnIndex As Integer = reader.GetOrdinal("City")
        Dim regionColumnIndex As Integer = reader.GetOrdinal("Region")
        Dim postalCodeColumnIndex As Integer = reader.GetOrdinal("PostalCode")
        Dim countryColumnIndex As Integer = reader.GetOrdinal("Country")

        Dim recordList As System.Collections.ArrayList = New System.Collections.ArrayList()
        Dim ri As Integer = -startIndex
        While(reader.Read())
            ri = ri + 1
            If ri > 0 AND ri <= length Then
                Dim record As OrdersQryRow = New OrdersQryRow()
                recordList.Add(record)

                record.OrderID = Convert.ToInt32(reader.GetValue(orderIDColumnIndex))
                If Not reader.IsDBNull(customerIDColumnIndex) Then
                    record.CustomerID = Convert.ToString(reader.GetValue(customerIDColumnIndex))
                End If
                If Not reader.IsDBNull(employeeIDColumnIndex) Then
                    record.EmployeeID = Convert.ToInt32(reader.GetValue(employeeIDColumnIndex))
                End If
                If Not reader.IsDBNull(orderDateColumnIndex) Then
                    record.OrderDate = Convert.ToDateTime(reader.GetValue(orderDateColumnIndex))
                End If
                If Not reader.IsDBNull(requiredDateColumnIndex) Then
                    record.RequiredDate = Convert.ToDateTime(reader.GetValue(requiredDateColumnIndex))
                End If
                If Not reader.IsDBNull(shippedDateColumnIndex) Then
                    record.ShippedDate = Convert.ToDateTime(reader.GetValue(shippedDateColumnIndex))
                End If
                If Not reader.IsDBNull(shipViaColumnIndex) Then
                    record.ShipVia = Convert.ToInt32(reader.GetValue(shipViaColumnIndex))
                End If
                If Not reader.IsDBNull(freightColumnIndex) Then
                    record.Freight = Convert.ToDecimal(reader.GetValue(freightColumnIndex))
                End If
                If Not reader.IsDBNull(shipNameColumnIndex) Then
                    record.ShipName = Convert.ToString(reader.GetValue(shipNameColumnIndex))
                End If
                If Not reader.IsDBNull(shipAddressColumnIndex) Then
                    record.ShipAddress = Convert.ToString(reader.GetValue(shipAddressColumnIndex))
                End If
                If Not reader.IsDBNull(shipCityColumnIndex) Then
                    record.ShipCity = Convert.ToString(reader.GetValue(shipCityColumnIndex))
                End If
                If Not reader.IsDBNull(shipRegionColumnIndex) Then
                    record.ShipRegion = Convert.ToString(reader.GetValue(shipRegionColumnIndex))
                End If
                If Not reader.IsDBNull(shipPostalCodeColumnIndex) Then
                    record.ShipPostalCode = Convert.ToString(reader.GetValue(shipPostalCodeColumnIndex))
                End If
                If Not reader.IsDBNull(shipCountryColumnIndex) Then
                    record.ShipCountry = Convert.ToString(reader.GetValue(shipCountryColumnIndex))
                End If
                record.CompanyName = Convert.ToString(reader.GetValue(companyNameColumnIndex))
                If Not reader.IsDBNull(addressColumnIndex) Then
                    record.Address = Convert.ToString(reader.GetValue(addressColumnIndex))
                End If
                If Not reader.IsDBNull(cityColumnIndex) Then
                    record.City = Convert.ToString(reader.GetValue(cityColumnIndex))
                End If
                If Not reader.IsDBNull(regionColumnIndex) Then
                    record.Region = Convert.ToString(reader.GetValue(regionColumnIndex))
                End If
                If Not reader.IsDBNull(postalCodeColumnIndex) Then
                    record.PostalCode = Convert.ToString(reader.GetValue(postalCodeColumnIndex))
                End If
                If Not reader.IsDBNull(countryColumnIndex) Then
                    record.Country = Convert.ToString(reader.GetValue(countryColumnIndex))
                End If

                If ri = length AND 0 <> totalRecordCount Then
                    Exit While
                End If
            End If
        End While
        
        If 0 = totalRecordCount
            totalRecordCount = ri + startIndex
        Else
            totalRecordCount = -1
        End If

        Return CType(recordList.ToArray(GetType(OrdersQryRow)), OrdersQryRow())
    End Function

    ''' <summary>
    ''' Reads data using the specified command and returns 
    ''' a filled <see cref="System.Data.DataTable"/> object.
    ''' </summary>
    ''' <param name="command">The <see cref="System.Data.IDbCommand"/> object.</param>
    ''' <returns>A reference to the <see cref="System.Data.DataTable"/> object.</returns>
    Protected Function MapRecordsToDataTable(command As IDbCommand) As DataTable
        Dim reader As IDataReader = _db.ExecuteReader(command)
        Try
            Return MapRecordsToDataTable(reader)
        Finally
            reader.Dispose()
        End Try
    End Function
    
    ''' <summary>
    ''' Reads data from the provided data reader and returns 
    ''' a filled <see cref="System.Data.DataTable"/> object.
    ''' </summary>
    ''' <param name="reader">The <see cref="System.Data.IDataReader"/> object to read data from the view.</param>
    ''' <returns>A reference to the <see cref="System.Data.DataTable"/> object.</returns>
    Protected Function MapRecordsToDataTable(reader As IDataReader) As DataTable
        Dim totalRecordCount As Integer = 0
        Return MapRecordsToDataTable(reader, 0, Integer.MaxValue, totalRecordCount)
    End Function
    
    ''' <summary>
    ''' Reads data from the provided data reader and returns 
    ''' a filled <see cref="System.Data.DataTable"/> object.
    ''' </summary>
    ''' <param name="reader">The <see cref="System.Data.IDataReader"/> object to read data from the view.</param>
    ''' <param name="startIndex">The index of the first record to read.</param>
    ''' <param name="length">The number of records to read.</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>
    Protected Overridable Function MapRecordsToDataTable(reader As IDataReader, startIndex As Integer, _
                            length As Integer, ByRef totalRecordCount As Integer) As DataTable
        If 0 > startIndex Then
            Throw New ArgumentOutOfRangeException("startIndex", startIndex, "StartIndex cannot be less than zero.")
        End If
        If 0 > length Then
            Throw New ArgumentOutOfRangeException("length", length, "Length cannot be less than zero.")
        End If

        Dim columnCount As Integer = reader.FieldCount
        Dim ri As Integer = -startIndex
        
        Dim dataTable As DataTable = CreateDataTable()
        dataTable.BeginLoadData()
        Dim values(columnCount - 1) As Object
        
        While(reader.Read())
            ri = ri + 1
            If ri > 0 AND ri <= length Then
                reader.GetValues(values)
                dataTable.LoadDataRow(values, True)

                If ri = length AND 0 <> totalRecordCount Then
                    Exit While
                End If
            End If
        End While
        dataTable.EndLoadData()

        If 0 = totalRecordCount
            totalRecordCount = ri + startIndex
        Else
            totalRecordCount = -1
        End If

        Return dataTable
    End Function

    ''' <summary>
    ''' Converts <see cref="System.Data.DataRow"/> to <see cref="OrdersQryRow"/>.
    ''' </summary>
    ''' <param name="row">The <see cref="System.Data.DataRow"/> object to be mapped.</param>
    ''' <returns>A reference to the <see cref="OrdersQryRow"/> object.</returns>
    Protected Overridable Function MapRow(row As DataRow) As OrdersQryRow
        Dim mappedObject As OrdersQryRow = New OrdersQryRow()
        Dim dataTable As DataTable = row.Table
        Dim dataColumn As DataColumn
        ' Column "OrderID"
        dataColumn = dataTable.Columns("OrderID")
        If Not row.IsNull(dataColumn) Then
            mappedObject.OrderID = CType(row(dataColumn), Integer)
        End If
        ' Column "CustomerID"
        dataColumn = dataTable.Columns("CustomerID")
        If Not row.IsNull(dataColumn) Then
            mappedObject.CustomerID = CType(row(dataColumn), String)
        End If
        ' Column "EmployeeID"
        dataColumn = dataTable.Columns("EmployeeID")
        If Not row.IsNull(dataColumn) Then
            mappedObject.EmployeeID = CType(row(dataColumn), Integer)
        End If
        ' Column "OrderDate"
        dataColumn = dataTable.Columns("OrderDate")
        If Not row.IsNull(dataColumn) Then
            mappedObject.OrderDate = CType(row(dataColumn), Date)
        End If
        ' Column "RequiredDate"
        dataColumn = dataTable.Columns("RequiredDate")
        If Not row.IsNull(dataColumn) Then
            mappedObject.RequiredDate = CType(row(dataColumn), Date)
        End If
        ' Column "ShippedDate"
        dataColumn = dataTable.Columns("ShippedDate")
        If Not row.IsNull(dataColumn) Then
            mappedObject.ShippedDate = CType(row(dataColumn), Date)
        End If
        ' Column "ShipVia"
        dataColumn = dataTable.Columns("ShipVia")
        If Not row.IsNull(dataColumn) Then
            mappedObject.ShipVia = CType(row(dataColumn), Integer)
        End If
        ' Column "Freight"
        dataColumn = dataTable.Columns("Freight")
        If Not row.IsNull(dataColumn) Then
            mappedObject.Freight = CType(row(dataColumn), Decimal)
        End If
        ' Column "ShipName"
        dataColumn = dataTable.Columns("ShipName")
        If Not row.IsNull(dataColumn) Then
            mappedObject.ShipName = CType(row(dataColumn), String)
        End If
        ' Column "ShipAddress"
        dataColumn = dataTable.Columns("ShipAddress")
        If Not row.IsNull(dataColumn) Then
            mappedObject.ShipAddress = CType(row(dataColumn), String)
        End If
        ' Column "ShipCity"
        dataColumn = dataTable.Columns("ShipCity")
        If Not row.IsNull(dataColumn) Then
            mappedObject.ShipCity = CType(row(dataColumn), String)
        End If
        ' Column "ShipRegion"
        dataColumn = dataTable.Columns("ShipRegion")
        If Not row.IsNull(dataColumn) Then
            mappedObject.ShipRegion = CType(row(dataColumn), String)
        End If
        ' Column "ShipPostalCode"
        dataColumn = dataTable.Columns("ShipPostalCode")
        If Not row.IsNull(dataColumn) Then
            mappedObject.ShipPostalCode = CType(row(dataColumn), String)
        End If
        ' Column "ShipCountry"
        dataColumn = dataTable.Columns("ShipCountry")
        If Not row.IsNull(dataColumn) Then
            mappedObject.ShipCountry = CType(row(dataColumn), String)
        End If
        ' Column "CompanyName"
        dataColumn = dataTable.Columns("CompanyName")
        If Not row.IsNull(dataColumn) Then
            mappedObject.CompanyName = CType(row(dataColumn), String)
        End If
        ' Column "Address"
        dataColumn = dataTable.Columns("Address")
        If Not row.IsNull(dataColumn) Then
            mappedObject.Address = CType(row(dataColumn), String)
        End If
        ' Column "City"
        dataColumn = dataTable.Columns("City")
        If Not row.IsNull(dataColumn) Then
            mappedObject.City = CType(row(dataColumn), String)
        End If
        ' Column "Region"
        dataColumn = dataTable.Columns("Region")
        If Not row.IsNull(dataColumn) Then
            mappedObject.Region = CType(row(dataColumn), String)
        End If
        ' Column "PostalCode"
        dataColumn = dataTable.Columns("PostalCode")
        If Not row.IsNull(dataColumn) Then
            mappedObject.PostalCode = CType(row(dataColumn), String)
        End If
        ' Column "Country"
        dataColumn = dataTable.Columns("Country")
        If Not row.IsNull(dataColumn) Then
            mappedObject.Country = CType(row(dataColumn), String)
        End If
        Return mappedObject
    End Function

    ''' <summary>
    ''' Creates a <see cref="System.Data.DataTable"/> object for 
    ''' the <c>Orders Qry</c> view.
    ''' </summary>
    ''' <returns>A reference to the <see cref="System.Data.DataTable"/> object.</returns>
    Protected Overridable Function CreateDataTable() As DataTable
        Dim dataTable As DataTable = new DataTable()
        dataTable.TableName = "OrdersQry"
        Dim dataColumn As DataColumn
        ' Create the "OrderID" column
        dataColumn = dataTable.Columns.Add("OrderID", GetType(Integer))
        dataColumn.AllowDBNull = False
        dataColumn.ReadOnly = True
        ' Create the "CustomerID" column
        dataColumn = dataTable.Columns.Add("CustomerID", GetType(String))
        dataColumn.MaxLength = 5
        dataColumn.ReadOnly = True
        ' Create the "EmployeeID" column
        dataColumn = dataTable.Columns.Add("EmployeeID", GetType(Integer))
        dataColumn.ReadOnly = True
        ' Create the "OrderDate" column
        dataColumn = dataTable.Columns.Add("OrderDate", GetType(Date))
        dataColumn.ReadOnly = True
        ' Create the "RequiredDate" column
        dataColumn = dataTable.Columns.Add("RequiredDate", GetType(Date))
        dataColumn.ReadOnly = True
        ' Create the "ShippedDate" column
        dataColumn = dataTable.Columns.Add("ShippedDate", GetType(Date))
        dataColumn.ReadOnly = True
        ' Create the "ShipVia" column
        dataColumn = dataTable.Columns.Add("ShipVia", GetType(Integer))
        dataColumn.ReadOnly = True
        ' Create the "Freight" column
        dataColumn = dataTable.Columns.Add("Freight", GetType(Decimal))
        dataColumn.ReadOnly = True
        ' Create the "ShipName" column
        dataColumn = dataTable.Columns.Add("ShipName", GetType(String))
        dataColumn.MaxLength = 40
        dataColumn.ReadOnly = True
        ' Create the "ShipAddress" column
        dataColumn = dataTable.Columns.Add("ShipAddress", GetType(String))
        dataColumn.MaxLength = 60
        dataColumn.ReadOnly = True
        ' Create the "ShipCity" column
        dataColumn = dataTable.Columns.Add("ShipCity", GetType(String))
        dataColumn.MaxLength = 15
        dataColumn.ReadOnly = True
        ' Create the "ShipRegion" column
        dataColumn = dataTable.Columns.Add("ShipRegion", GetType(String))
        dataColumn.MaxLength = 15
        dataColumn.ReadOnly = True
        ' Create the "ShipPostalCode" column
        dataColumn = dataTable.Columns.Add("ShipPostalCode", GetType(String))
        dataColumn.MaxLength = 10
        dataColumn.ReadOnly = True
        ' Create the "ShipCountry" column
        dataColumn = dataTable.Columns.Add("ShipCountry", GetType(String))
        dataColumn.MaxLength = 15
        dataColumn.ReadOnly = True
        ' Create the "CompanyName" column
        dataColumn = dataTable.Columns.Add("CompanyName", GetType(String))
        dataColumn.MaxLength = 40
        dataColumn.AllowDBNull = False
        dataColumn.ReadOnly = True
        ' Create the "Address" column
        dataColumn = dataTable.Columns.Add("Address", GetType(String))
        dataColumn.MaxLength = 60
        dataColumn.ReadOnly = True
        ' Create the "City" column
        dataColumn = dataTable.Columns.Add("City", GetType(String))
        dataColumn.MaxLength = 15
        dataColumn.ReadOnly = True
        ' Create the "Region" column
        dataColumn = dataTable.Columns.Add("Region", GetType(String))
        dataColumn.MaxLength = 15
        dataColumn.ReadOnly = True
        ' Create the "PostalCode" column
        dataColumn = dataTable.Columns.Add("PostalCode", GetType(String))
        dataColumn.MaxLength = 10
        dataColumn.ReadOnly = True
        ' Create the "Country" column
        dataColumn = dataTable.Columns.Add("Country", GetType(String))
        dataColumn.MaxLength = 15
        dataColumn.ReadOnly = True
        Return dataTable
    End Function
    
    ''' <summary>
    ''' Adds a new parameter to the specified command.
    ''' </summary>
    ''' <param name="cmd">The <see cref="System.Data.IDbCommand"/> object to add the parameter to.</param>
    ''' <param name="paramName">The name of the parameter.</param>
    ''' <param name="value">The value of the parameter.</param>
    ''' <returns>A reference to the added parameter.</returns>
    Protected Overridable Function AddParameter(cmd As IDbCommand, paramName As String, _
                                value As Object) As IDbDataParameter
        Dim parameter As IDbDataParameter
        Select paramName
            Case "OrderID"
                parameter = _db.AddParameter(cmd, paramName, DbType.Int32, value)
            Case "CustomerID"
                parameter = _db.AddParameter(cmd, paramName, DbType.StringFixedLength, value)
            Case "EmployeeID"
                parameter = _db.AddParameter(cmd, paramName, DbType.Int32, value)
            Case "OrderDate"
                parameter = _db.AddParameter(cmd, paramName, DbType.DateTime, value)
            Case "RequiredDate"
                parameter = _db.AddParameter(cmd, paramName, DbType.DateTime, value)
            Case "ShippedDate"
                parameter = _db.AddParameter(cmd, paramName, DbType.DateTime, value)
            Case "ShipVia"
                parameter = _db.AddParameter(cmd, paramName, DbType.Int32, value)
            Case "Freight"
                parameter = _db.AddParameter(cmd, paramName, DbType.Currency, value)
            Case "ShipName"
                parameter = _db.AddParameter(cmd, paramName, DbType.String, value)
            Case "ShipAddress"
                parameter = _db.AddParameter(cmd, paramName, DbType.String, value)
            Case "ShipCity"
                parameter = _db.AddParameter(cmd, paramName, DbType.String, value)
            Case "ShipRegion"
                parameter = _db.AddParameter(cmd, paramName, DbType.String, value)
            Case "ShipPostalCode"
                parameter = _db.AddParameter(cmd, paramName, DbType.String, value)
            Case "ShipCountry"
                parameter = _db.AddParameter(cmd, paramName, DbType.String, value)
            Case "CompanyName"
                parameter = _db.AddParameter(cmd, paramName, DbType.String, value)
            Case "Address"
                parameter = _db.AddParameter(cmd, paramName, DbType.String, value)
            Case "City"
                parameter = _db.AddParameter(cmd, paramName, DbType.String, value)
            Case "Region"
                parameter = _db.AddParameter(cmd, paramName, DbType.String, value)
            Case "PostalCode"
                parameter = _db.AddParameter(cmd, paramName, DbType.String, value)
            Case "Country"
                parameter = _db.AddParameter(cmd, paramName, DbType.String, value)
            Case Else
                Throw New ArgumentException("Unknown parameter name (" + paramName + ").")
        End Select
        Return parameter
    End Function
End Class