// <fileinfo name="OrdersCollection_Base.cs">
//      <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>

using System;
using System.Data;

namespace MyCompany.MyProject.Db
{
    /// <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 abstract class OrdersCollection_Base
    {
        // Constants
        public const string OrderIDColumnName = "OrderID";
        public const string CustomerIDColumnName = "CustomerID";
        public const string EmployeeIDColumnName = "EmployeeID";
        public const string OrderDateColumnName = "OrderDate";
        public const string RequiredDateColumnName = "RequiredDate";
        public const string ShippedDateColumnName = "ShippedDate";
        public const string ShipViaColumnName = "ShipVia";
        public const string FreightColumnName = "Freight";
        public const string ShipNameColumnName = "ShipName";
        public const string ShipAddressColumnName = "ShipAddress";
        public const string ShipCityColumnName = "ShipCity";
        public const string ShipRegionColumnName = "ShipRegion";
        public const string ShipPostalCodeColumnName = "ShipPostalCode";
        public const string ShipCountryColumnName = "ShipCountry";

        // Instance fields
        private Northwind _db;

        /// <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 OrdersCollection_Base(Northwind db)
        {
            _db = db;
        }

        /// <summary>
        /// Gets the database object that this table belongs to.
        /// </summary>
        /// <value>The <see cref="Northwind"/> object.</value>
        protected Northwind Database
        {
            get { return _db; }
        }

        /// <summary>
        /// Gets an array of all records from the <c>Orders</c> table.
        /// </summary>
        /// <returns>An array of <see cref="OrdersRow"/> objects.</returns>
        public virtual OrdersRow[] GetAll()
        {
            return MapRecords(CreateGetAllCommand());
        }

        /// <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 virtual DataTable GetAllAsDataTable()
        {
            return MapRecordsToDataTable(CreateGetAllCommand());
        }

        /// <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 virtual IDbCommand CreateGetAllCommand()
        {
            return _db.CreateCommand("dbo._Orders_GetAll", true);
        }

        /// <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 OrdersRow GetRow(string whereSql)
        {
            int totalRecordCount = -1;
            OrdersRow[] rows = GetAsArray(whereSql, null, 0, 1, ref totalRecordCount);
            return 0 == rows.Length ? null : rows[0];
        }

        /// <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 OrdersRow[] GetAsArray(string whereSql, string orderBySql)
        {
            int totalRecordCount = -1;
            return GetAsArray(whereSql, orderBySql, 0, int.MaxValue, ref totalRecordCount);
        }

        /// <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 virtual OrdersRow[] GetAsArray(string whereSql, string orderBySql,
                            int startIndex, int length, ref int totalRecordCount)
        {
            using(IDataReader reader = _db.ExecuteReader(CreateGetCommand(whereSql, orderBySql)))
            {
                return MapRecords(reader, startIndex, length, ref totalRecordCount);
            }
        }

        /// <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 DataTable GetAsDataTable(string whereSql, string orderBySql)
        {
            int totalRecordCount = -1;
            return GetAsDataTable(whereSql, orderBySql, 0, int.MaxValue, ref totalRecordCount);
        }

        /// <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 virtual DataTable GetAsDataTable(string whereSql, string orderBySql,
                            int startIndex, int length, ref int totalRecordCount)
        {
            using(IDataReader reader = _db.ExecuteReader(CreateGetCommand(whereSql, orderBySql)))
            {
                return MapRecordsToDataTable(reader, startIndex, length, ref totalRecordCount);
            }
        }

        /// <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 virtual IDbCommand CreateGetCommand(string whereSql, string orderBySql)
        {
            string sql = "SELECT * FROM [dbo].[Orders]";
            if(null != whereSql && 0 < whereSql.Length)
                sql += " WHERE " + whereSql;
            if(null != orderBySql && 0 < orderBySql.Length)
                sql += " ORDER BY " + orderBySql;
            return _db.CreateCommand(sql);
        }

        /// <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 virtual OrdersRow GetByPrimaryKey(int orderID)
        {
            IDbCommand cmd = _db.CreateCommand("dbo._Orders_GetByPrimaryKey", true);
            AddParameter(cmd, "OrderID", orderID);
            OrdersRow[] tempArray = MapRecords(cmd);
            return 0 == tempArray.Length ? null : tempArray[0];
        }

        /// <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 virtual OrdersRow[] GetByCustomerID(string customerID)
        {
            return MapRecords(CreateGetByCustomerIDCommand(customerID));
        }

        /// <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 virtual DataTable GetByCustomerIDAsDataTable(string customerID)
        {
            return MapRecordsToDataTable(CreateGetByCustomerIDCommand(customerID));
        }

        /// <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 virtual IDbCommand CreateGetByCustomerIDCommand(string customerID)
        {
            IDbCommand cmd = _db.CreateCommand("dbo._Orders_GetBy_CustomerID", true);
            AddParameter(cmd, "CustomerID", customerID);
            return cmd;
        }

        /// <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 OrdersRow[] GetByEmployeeID(int employeeID)
        {
            return GetByEmployeeID(employeeID, false);
        }

        /// <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 virtual OrdersRow[] GetByEmployeeID(int employeeID, bool employeeIDNull)
        {
            return MapRecords(CreateGetByEmployeeIDCommand(employeeID, employeeIDNull));
        }

        /// <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 DataTable GetByEmployeeIDAsDataTable(int employeeID)
        {
            return GetByEmployeeIDAsDataTable(employeeID, false);
        }

        /// <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 virtual DataTable GetByEmployeeIDAsDataTable(int employeeID, bool employeeIDNull)
        {
            return MapRecordsToDataTable(CreateGetByEmployeeIDCommand(employeeID, employeeIDNull));
        }

        /// <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 virtual IDbCommand CreateGetByEmployeeIDCommand(int employeeID, bool employeeIDNull)
        {
            IDbCommand cmd = _db.CreateCommand("dbo._Orders_GetBy_EmployeeID", true);
            AddParameter(cmd, "EmployeeID", employeeIDNull ? null : (object)employeeID);
            return cmd;
        }

        /// <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 OrdersRow[] GetByShipVia(int shipVia)
        {
            return GetByShipVia(shipVia, false);
        }

        /// <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 virtual OrdersRow[] GetByShipVia(int shipVia, bool shipViaNull)
        {
            return MapRecords(CreateGetByShipViaCommand(shipVia, shipViaNull));
        }

        /// <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 DataTable GetByShipViaAsDataTable(int shipVia)
        {
            return GetByShipViaAsDataTable(shipVia, false);
        }

        /// <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 virtual DataTable GetByShipViaAsDataTable(int shipVia, bool shipViaNull)
        {
            return MapRecordsToDataTable(CreateGetByShipViaCommand(shipVia, shipViaNull));
        }

        /// <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 virtual IDbCommand CreateGetByShipViaCommand(int shipVia, bool shipViaNull)
        {
            IDbCommand cmd = _db.CreateCommand("dbo._Orders_GetBy_ShipVia", true);
            AddParameter(cmd, "ShipVia", shipViaNull ? null : (object)shipVia);
            return cmd;
        }

        /// <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 virtual void Insert(OrdersRow value)
        {
            IDbCommand cmd = _db.CreateCommand("dbo._Orders_Insert", true);
            AddParameter(cmd, "CustomerID", value.CustomerID);
            AddParameter(cmd, "EmployeeID",
                value.IsEmployeeIDNull ? DBNull.Value : (object)value.EmployeeID);
            AddParameter(cmd, "OrderDate",
                value.IsOrderDateNull ? DBNull.Value : (object)value.OrderDate);
            AddParameter(cmd, "RequiredDate",
                value.IsRequiredDateNull ? DBNull.Value : (object)value.RequiredDate);
            AddParameter(cmd, "ShippedDate",
                value.IsShippedDateNull ? DBNull.Value : (object)value.ShippedDate);
            AddParameter(cmd, "ShipVia",
                value.IsShipViaNull ? DBNull.Value : (object)value.ShipVia);
            AddParameter(cmd, "Freight",
                value.IsFreightNull ? DBNull.Value : (object)value.Freight);
            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());
        }

        /// <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 virtual bool Update(OrdersRow value)
        {
            IDbCommand cmd = _db.CreateCommand("dbo._Orders_Update", true);
            AddParameter(cmd, "CustomerID", value.CustomerID);
            AddParameter(cmd, "EmployeeID",
                value.IsEmployeeIDNull ? DBNull.Value : (object)value.EmployeeID);
            AddParameter(cmd, "OrderDate",
                value.IsOrderDateNull ? DBNull.Value : (object)value.OrderDate);
            AddParameter(cmd, "RequiredDate",
                value.IsRequiredDateNull ? DBNull.Value : (object)value.RequiredDate);
            AddParameter(cmd, "ShippedDate",
                value.IsShippedDateNull ? DBNull.Value : (object)value.ShippedDate);
            AddParameter(cmd, "ShipVia",
                value.IsShipViaNull ? DBNull.Value : (object)value.ShipVia);
            AddParameter(cmd, "Freight",
                value.IsFreightNull ? DBNull.Value : (object)value.Freight);
            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();
        }

        /// <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 void Update(DataTable table)
        {
            Update(table, true);
        }

        /// <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 virtual void Update(DataTable table, bool acceptChanges)
        {
            DataRowCollection rows = table.Rows;
            for(int i = rows.Count - 1; i >= 0; i--)
            {
                DataRow row = rows[i];
                switch(row.RowState)
                {
                    case DataRowState.Added:
                        Insert(MapRow(row));
                        if(acceptChanges)
                            row.AcceptChanges();
                        break;

                    case DataRowState.Deleted:
                        // Temporary reject changes to be able to access to the PK column(s)
                        row.RejectChanges();
                        try
                        {
                            DeleteByPrimaryKey((int)row["OrderID"]);
                        }
                        finally
                        {
                            row.Delete();
                        }
                        if(acceptChanges)
                            row.AcceptChanges();
                        break;
                        
                    case DataRowState.Modified:
                        Update(MapRow(row));
                        if(acceptChanges)
                            row.AcceptChanges();
                        break;
                }
            }
        }

        /// <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 bool Delete(OrdersRow value)
        {
            return DeleteByPrimaryKey(value.OrderID);
        }

        /// <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 virtual bool DeleteByPrimaryKey(int orderID)
        {
            IDbCommand cmd = _db.CreateCommand("dbo._Orders_DeleteByPrimaryKey", true);
            AddParameter(cmd, "OrderID", orderID);
            return 0 < cmd.ExecuteNonQuery();
        }

        /// <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 int DeleteByCustomerID(string customerID)
        {
            return CreateDeleteByCustomerIDCommand(customerID).ExecuteNonQuery();
        }

        /// <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>
        protected virtual IDbCommand CreateDeleteByCustomerIDCommand(string customerID)
        {
            IDbCommand cmd = _db.CreateCommand("dbo._Orders_DeleteBy_CustomerID", true);
            AddParameter(cmd, "CustomerID", customerID);
            return cmd;
        }

        /// <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 int DeleteByEmployeeID(