// <fileinfo name="OrdersQryCollection_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="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 abstract class OrdersQryCollection_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";
public const string CompanyNameColumnName = "CompanyName";
public const string AddressColumnName = "Address";
public const string CityColumnName = "City";
public const string RegionColumnName = "Region";
public const string PostalCodeColumnName = "PostalCode";
public const string CountryColumnName = "Country";
// Instance fields
private Northwind _db;
/// <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 OrdersQryCollection_Base(Northwind db)
{
_db = db;
}
/// <summary>
/// Gets the database object that this view 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 Qry</c> view.
/// </summary>
/// <returns>An array of <see cref="OrdersQryRow"/> objects.</returns>
public virtual OrdersQryRow[] GetAll()
{
return MapRecords(CreateGetAllCommand());
}
/// <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 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 Qry</c> view.
/// </summary>
/// <returns>A reference to the <see cref="System.Data.IDbCommand"/> object.</returns>
protected virtual IDbCommand CreateGetAllCommand()
{
return CreateGetCommand(null, null);
}
/// <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 OrdersQryRow GetRow(string whereSql)
{
int totalRecordCount = -1;
OrdersQryRow[] rows = GetAsArray(whereSql, null, 0, 1, ref totalRecordCount);
return 0 == rows.Length ? null : rows[0];
}
/// <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 OrdersQryRow[] GetAsArray(string whereSql, string orderBySql)
{
int totalRecordCount = -1;
return GetAsArray(whereSql, orderBySql, 0, int.MaxValue, ref totalRecordCount);
}
/// <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 virtual OrdersQryRow[] 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 Qry]";
if(null != whereSql && 0 < whereSql.Length)
sql += " WHERE " + whereSql;
if(null != orderBySql && 0 < orderBySql.Length)
sql += " ORDER BY " + orderBySql;
return _db.CreateCommand(sql);
}
/// <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 OrdersQryRow[] MapRecords(IDbCommand command)
{
using(IDataReader reader = _db.ExecuteReader(command))
{
return MapRecords(reader);
}
}
/// <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 OrdersQryRow[] MapRecords(IDataReader reader)
{
int totalRecordCount = -1;
return MapRecords(reader, 0, int.MaxValue, ref totalRecordCount);
}
/// <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 virtual OrdersQryRow[] MapRecords(IDataReader reader,
int startIndex, int length, ref int totalRecordCount)
{
if(0 > startIndex)
throw new ArgumentOutOfRangeException("startIndex", startIndex, "StartIndex cannot be less than zero.");
if(0 > length)
throw new ArgumentOutOfRangeException("length", length, "Length cannot be less than zero.");
int orderIDColumnIndex = reader.GetOrdinal("OrderID");
int customerIDColumnIndex = reader.GetOrdinal("CustomerID");
int employeeIDColumnIndex = reader.GetOrdinal("EmployeeID");
int orderDateColumnIndex = reader.GetOrdinal("OrderDate");
int requiredDateColumnIndex = reader.GetOrdinal("RequiredDate");
int shippedDateColumnIndex = reader.GetOrdinal("ShippedDate");
int shipViaColumnIndex = reader.GetOrdinal("ShipVia");
int freightColumnIndex = reader.GetOrdinal("Freight");
int shipNameColumnIndex = reader.GetOrdinal("ShipName");
int shipAddressColumnIndex = reader.GetOrdinal("ShipAddress");
int shipCityColumnIndex = reader.GetOrdinal("ShipCity");
int shipRegionColumnIndex = reader.GetOrdinal("ShipRegion");
int shipPostalCodeColumnIndex = reader.GetOrdinal("ShipPostalCode");
int shipCountryColumnIndex = reader.GetOrdinal("ShipCountry");
int companyNameColumnIndex = reader.GetOrdinal("CompanyName");
int addressColumnIndex = reader.GetOrdinal("Address");
int cityColumnIndex = reader.GetOrdinal("City");
int regionColumnIndex = reader.GetOrdinal("Region");
int postalCodeColumnIndex = reader.GetOrdinal("PostalCode");
int countryColumnIndex = reader.GetOrdinal("Country");
System.Collections.ArrayList recordList = new System.Collections.ArrayList();
int ri = -startIndex;
while(reader.Read())
{
ri++;
if(ri > 0 && ri <= length)
{
OrdersQryRow record = new OrdersQryRow();
recordList.Add(record);
record.OrderID = Convert.ToInt32(reader.GetValue(orderIDColumnIndex));
if(!reader.IsDBNull(customerIDColumnIndex))
record.CustomerID = Convert.ToString(reader.GetValue(customerIDColumnIndex));
if(!reader.IsDBNull(employeeIDColumnIndex))
record.EmployeeID = Convert.ToInt32(reader.GetValue(employeeIDColumnIndex));
if(!reader.IsDBNull(orderDateColumnIndex))
record.OrderDate = Convert.ToDateTime(reader.GetValue(orderDateColumnIndex));
if(!reader.IsDBNull(requiredDateColumnIndex))
record.RequiredDate = Convert.ToDateTime(reader.GetValue(requiredDateColumnIndex));
if(!reader.IsDBNull(shippedDateColumnIndex))
record.ShippedDate = Convert.ToDateTime(reader.GetValue(shippedDateColumnIndex));
if(!reader.IsDBNull(shipViaColumnIndex))
record.ShipVia = Convert.ToInt32(reader.GetValue(shipViaColumnIndex));
if(!reader.IsDBNull(freightColumnIndex))
record.Freight = Convert.ToDecimal(reader.GetValue(freightColumnIndex));
if(!reader.IsDBNull(shipNameColumnIndex))
record.ShipName = Convert.ToString(reader.GetValue(shipNameColumnIndex));
if(!reader.IsDBNull(shipAddressColumnIndex))
record.ShipAddress = Convert.ToString(reader.GetValue(shipAddressColumnIndex));
if(!reader.IsDBNull(shipCityColumnIndex))
record.ShipCity = Convert.ToString(reader.GetValue(shipCityColumnIndex));
if(!reader.IsDBNull(shipRegionColumnIndex))
record.ShipRegion = Convert.ToString(reader.GetValue(shipRegionColumnIndex));
if(!reader.IsDBNull(shipPostalCodeColumnIndex))
record.ShipPostalCode = Convert.ToString(reader.GetValue(shipPostalCodeColumnIndex));
if(!reader.IsDBNull(shipCountryColumnIndex))
record.ShipCountry = Convert.ToString(reader.GetValue(shipCountryColumnIndex));
record.CompanyName = Convert.ToString(reader.GetValue(companyNameColumnIndex));
if(!reader.IsDBNull(addressColumnIndex))
record.Address = Convert.ToString(reader.GetValue(addressColumnIndex));
if(!reader.IsDBNull(cityColumnIndex))
record.City = Convert.ToString(reader.GetValue(cityColumnIndex));
if(!reader.IsDBNull(regionColumnIndex))
record.Region = Convert.ToString(reader.GetValue(regionColumnIndex));
if(!reader.IsDBNull(postalCodeColumnIndex))
record.PostalCode = Convert.ToString(reader.GetValue(postalCodeColumnIndex));
if(!reader.IsDBNull(countryColumnIndex))
record.Country = Convert.ToString(reader.GetValue(countryColumnIndex));
if(ri == length && 0 != totalRecordCount)
break;
}
}
totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1;
return (OrdersQryRow[])(recordList.ToArray(typeof(OrdersQryRow)));
}
/// <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 DataTable MapRecordsToDataTable(IDbCommand command)
{
using(IDataReader reader = _db.ExecuteReader(command))
{
return MapRecordsToDataTable(reader);
}
}
/// <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 DataTable MapRecordsToDataTable(IDataReader reader)
{
int totalRecordCount = 0;
return MapRecordsToDataTable(reader, 0, int.MaxValue, ref totalRecordCount);
}
/// <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 virtual DataTable MapRecordsToDataTable(IDataReader reader,
int startIndex, int length, ref int totalRecordCount)
{
if(0 > startIndex)
throw new ArgumentOutOfRangeException("startIndex", startIndex, "StartIndex cannot be less than zero.");
if(0 > length)
throw new ArgumentOutOfRangeException("length", length, "Length cannot be less than zero.");
int columnCount = reader.FieldCount;
int ri = -startIndex;
DataTable dataTable = CreateDataTable();
dataTable.BeginLoadData();
object[] values = new object[columnCount];
while(reader.Read())
{
ri++;
if(ri > 0 && ri <= length)
{
reader.GetValues(values);
dataTable.LoadDataRow(values, true);
if(ri == length && 0 != totalRecordCount)
break;
}
}
dataTable.EndLoadData();
totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1;
return dataTable;
}
/// <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 virtual OrdersQryRow MapRow(DataRow row)
{
OrdersQryRow mappedObject = new OrdersQryRow();
DataTable dataTable = row.Table;
DataColumn dataColumn;
// Column "OrderID"
dataColumn = dataTable.Columns["OrderID"];
if(!row.IsNull(dataColumn))
mappedObject.OrderID = (int)row[dataColumn];
// Column "CustomerID"
dataColumn = dataTable.Columns["CustomerID"];
if(!row.IsNull(dataColumn))
mappedObject.CustomerID = (string)row[dataColumn];
// Column "EmployeeID"
dataColumn = dataTable.Columns["EmployeeID"];
if(!row.IsNull(dataColumn))
mappedObject.EmployeeID = (int)row[dataColumn];
// Column "OrderDate"
dataColumn = dataTable.Columns["OrderDate"];
if(!row.IsNull(dataColumn))
mappedObject.OrderDate = (System.DateTime)row[dataColumn];
// Column "RequiredDate"
dataColumn = dataTable.Columns["RequiredDate"];
if(!row.IsNull(dataColumn))
mappedObject.RequiredDate = (System.DateTime)row[dataColumn];
// Column "ShippedDate"
dataColumn = dataTable.Columns["ShippedDate"];
if(!row.IsNull(dataColumn))
mappedObject.ShippedDate = (System.DateTime)row[dataColumn];
// Column "ShipVia"
dataColumn = dataTable.Columns["ShipVia"];
if(!row.IsNull(dataColumn))
mappedObject.ShipVia = (int)row[dataColumn];
// Column "Freight"
dataColumn = dataTable.Columns["Freight"];
if(!row.IsNull(dataColumn))
mappedObject.Freight = (decimal)row[dataColumn];
// Column "ShipName"
dataColumn = dataTable.Columns["ShipName"];
if(!row.IsNull(dataColumn))
mappedObject.ShipName = (string)row[dataColumn];
// Column "ShipAddress"
dataColumn = dataTable.Columns["ShipAddress"];
if(!row.IsNull(dataColumn))
mappedObject.ShipAddress = (string)row[dataColumn];
// Column "ShipCity"
dataColumn = dataTable.Columns["ShipCity"];
if(!row.IsNull(dataColumn))
mappedObject.ShipCity = (string)row[dataColumn];
// Column "ShipRegion"
dataColumn = dataTable.Columns["ShipRegion"];
if(!row.IsNull(dataColumn))
mappedObject.ShipRegion = (string)row[dataColumn];
// Column "ShipPostalCode"
dataColumn = dataTable.Columns["ShipPostalCode"];
if(!row.IsNull(dataColumn))
mappedObject.ShipPostalCode = (string)row[dataColumn];
// Column "ShipCountry"
dataColumn = dataTable.Columns["ShipCountry"];
if(!row.IsNull(dataColumn))
mappedObject.ShipCountry = (string)row[dataColumn];
// Column "CompanyName"
dataColumn = dataTable.Columns["CompanyName"];
if(!row.IsNull(dataColumn))
mappedObject.CompanyName = (string)row[dataColumn];
// Column "Address"
dataColumn = dataTable.Columns["Address"];
if(!row.IsNull(dataColumn))
mappedObject.Address = (string)row[dataColumn];
// Column "City"
dataColumn = dataTable.Columns["City"];
if(!row.IsNull(dataColumn))
mappedObject.City = (string)row[dataColumn];
// Column "Region"
dataColumn = dataTable.Columns["Region"];
if(!row.IsNull(dataColumn))
mappedObject.Region = (string)row[dataColumn];
// Column "PostalCode"
dataColumn = dataTable.Columns["PostalCode"];
if(!row.IsNull(dataColumn))
mappedObject.PostalCode = (string)row[dataColumn];
// Column "Country"
dataColumn = dataTable.Columns["Country"];
if(!row.IsNull(dataColumn))
mappedObject.Country = (string)row[dataColumn];
return mappedObject;
}
/// <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 virtual DataTable CreateDataTable()
{
DataTable dataTable = new DataTable();
dataTable.TableName = "OrdersQry";
DataColumn dataColumn;
dataColumn = dataTable.Columns.Add