context: using System;
  using System.Text;
  using System.Data;
  using System.Data.SqlClient;
  using System.Data.Common;
  using System.Collections;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Configuration;
  using System.Xml;
  using System.Xml.Serialization;
  using SubSonic;
  using SubSonic.Utilities;
  
  namespace TerritorySite.BL.CMS
  {
      /// <summary>
      /// Strongly-typed collection for the Territory class.
      /// </summary>
      [Serializable]
      public partial class TerritoryCollection : ActiveList<Territory, TerritoryCollection>
      {
          public TerritoryCollection() { }
  
      }
  
      /// <summary>
      /// This is an ActiveRecord class which wraps the Territory table.
      /// </summary>
      [Serializable]
      public partial class Territory : ActiveRecord<Territory>
      {
          #region .ctors and Default Settings
  
          public Territory()
          {
              SetSQLProps();
              InitSetDefaults();
              MarkNew();
          }
  
  
          private void InitSetDefaults() { SetDefaults(); }
  
  
          public Territory(bool useDatabaseDefaults)
          {
              SetSQLProps();
              if (useDatabaseDefaults)
                  ForceDefaults();
              MarkNew();
          }
  
          public Territory(object keyID)
          {
              SetSQLProps();
              InitSetDefaults();
              LoadByKey(keyID);
          }
  
  
          public Territory(string columnName, object columnValue)
          {
              SetSQLProps();
              InitSetDefaults();
              LoadByParam(columnName, columnValue);
          }
  
  
          protected static void SetSQLProps() { GetTableSchema(); }
  
  
          #endregion
  
          #region Schema and Query Accessor
          public static Query CreateQuery() { return new Query(Schema); }
  
  
          public static TableSchema.Table Schema
          {
              get
              {
                  if (BaseSchema == null)
                      SetSQLProps();
                  return BaseSchema;
              }
  
          }
  
  
          private static void GetTableSchema()
          {
              if (!IsSchemaInitialized)
              {
                  //Schema declaration
                  TableSchema.Table schema = new TableSchema.Table("Territory", TableType.Table, DataService.GetInstance("CMS"));
                  schema.Columns = new TableSchema.TableColumnCollection();
                  schema.SchemaName = @"dbo";
                  //columns
  
                  TableSchema.TableColumn colvarTerritoryId = new TableSchema.TableColumn(schema);
                  colvarTerritoryId.ColumnName = "TerritoryId";
                  colvarTerritoryId.DataType = DbType.Int32;
                  colvarTerritoryId.MaxLength = 0;
                  colvarTerritoryId.AutoIncrement = true;
                  colvarTerritoryId.IsNullable = false;
                  colvarTerritoryId.IsPrimaryKey = true;
                  colvarTerritoryId.IsForeignKey = false;
                  colvarTerritoryId.IsReadOnly = false;
                  colvarTerritoryId.DefaultSetting = @"";
                  colvarTerritoryId.ForeignKeyTableName = "";
                  schema.Columns.Add(colvarTerritoryId);
  
                  TableSchema.TableColumn colvarTerritoryNumber = new TableSchema.TableColumn(schema);
                  colvarTerritoryNumber.ColumnName = "TerritoryNumber";
                  colvarTerritoryNumber.DataType = DbType.Int32;
                  colvarTerritoryNumber.MaxLength = 0;
                  colvarTerritoryNumber.AutoIncrement = false;
                  colvarTerritoryNumber.IsNullable = false;
                  colvarTerritoryNumber.IsPrimaryKey = false;
                  colvarTerritoryNumber.IsForeignKey = false;
                  colvarTerritoryNumber.IsReadOnly = false;
                  colvarTerritoryNumber.DefaultSetting = @"";
                  colvarTerritoryNumber.ForeignKeyTableName = "";
                  schema.Columns.Add(colvarTerritoryNumber);
  
                  TableSchema.TableColumn colvarDescription = new TableSchema.TableColumn(schema);
                  colvarDescription.ColumnName = "Description";
                  colvarDescription.DataType = DbType.String;
                  colvarDescription.MaxLength = 500;
                  colvarDescription.AutoIncrement = false;
                  colvarDescription.IsNullable = true;
                  colvarDescription.IsPrimaryKey = false;
                  colvarDescription.IsForeignKey = false;
                  colvarDescription.IsReadOnly = false;
                  colvarDescription.DefaultSetting = @"";
                  colvarDescription.ForeignKeyTableName = "";
                  schema.Columns.Add(colvarDescription);
  
                  TableSchema.TableColumn colvarAccountId = new TableSchema.TableColumn(schema);
                  colvarAccountId.ColumnName = "AccountId";
                  colvarAccountId.DataType = DbType.Int32;
                  colvarAccountId.MaxLength = 0;
                  colvarAccountId.AutoIncrement = false;
                  colvarAccountId.IsNullable = false;
                  colvarAccountId.IsPrimaryKey = false;
                  colvarAccountId.IsForeignKey = true;
                  colvarAccountId.IsReadOnly = false;
                  colvarAccountId.DefaultSetting = @"";
  
                  colvarAccountId.ForeignKeyTableName = "Account";
                  schema.Columns.Add(colvarAccountId);
  
                  TableSchema.TableColumn colvarCoordinatesPerimeter = new TableSchema.TableColumn(schema);
                  colvarCoordinatesPerimeter.ColumnName = "CoordinatesPerimeter";
                  colvarCoordinatesPerimeter.DataType = DbType.String;
                  colvarCoordinatesPerimeter.MaxLength = 2147483647;
                  colvarCoordinatesPerimeter.AutoIncrement = false;
                  colvarCoordinatesPerimeter.IsNullable = true;
                  colvarCoordinatesPerimeter.IsPrimaryKey = false;
                  colvarCoordinatesPerimeter.IsForeignKey = false;
                  colvarCoordinatesPerimeter.IsReadOnly = false;
                  colvarCoordinatesPerimeter.DefaultSetting = @"";
                  colvarCoordinatesPerimeter.ForeignKeyTableName = "";
                  schema.Columns.Add(colvarCoordinatesPerimeter);
  
                  TableSchema.TableColumn colvarCoordinatesCenter = new TableSchema.TableColumn(schema);
                  colvarCoordinatesCenter.ColumnName = "CoordinatesCenter";
                  colvarCoordinatesCenter.DataType = DbType.String;
                  colvarCoordinatesCenter.MaxLength = 50;
                  colvarCoordinatesCenter.AutoIncrement = false;
                  colvarCoordinatesCenter.IsNullable = true;
                  colvarCoordinatesCenter.IsPrimaryKey = false;
                  colvarCoordinatesCenter.IsForeignKey = false;
                  colvarCoordinatesCenter.IsReadOnly = false;
                  colvarCoordinatesCenter.DefaultSetting = @"";
                  colvarCoordinatesCenter.ForeignKeyTableName = "";
                  schema.Columns.Add(colvarCoordinatesCenter);
  
                  TableSchema.TableColumn colvarPortrait = new TableSchema.TableColumn(schema);
                  colvarPortrait.ColumnName = "Portrait";
                  colvarPortrait.DataType = DbType.Boolean;
                  colvarPortrait.MaxLength = 0;
                  colvarPortrait.AutoIncrement = false;
                  colvarPortrait.IsNullable = true;
                  colvarPortrait.IsPrimaryKey = false;
                  colvarPortrait.IsForeignKey = false;
                  colvarPortrait.IsReadOnly = false;
                  colvarPortrait.DefaultSetting = @"";
                  colvarPortrait.ForeignKeyTableName = "";
                  schema.Columns.Add(colvarPortrait);
  
                  BaseSchema = schema;
                  //add this schema to the provider
                  //so we can query it later
                  DataService.Providers["CMS"].AddSchema("Territory", schema);
              }
  
          }
  
          #endregion
  
          #region Props
  
  
          [XmlAttribute("TerritoryId")]
          public int TerritoryId
          {
              get { return GetColumnValue<int>("TerritoryId"); }
  
              set { SetColumnValue("TerritoryId", value); }
  
          }
  
  
          [XmlAttribute("TerritoryNumber")]
          public int TerritoryNumber
          {
              get { return GetColumnValue<int>("TerritoryNumber"); }
  
              set { SetColumnValue("TerritoryNumber", value); }
  
          }
  
  
          [XmlAttribute("Description")]
          public string Description
          {
              get { return GetColumnValue<string>("Description"); }
  
              set { SetColumnValue("Description", value); }
  
          }
  
  
          [XmlAttribute("AccountId")]
          public int AccountId
          {
              get { return GetColumnValue<int>("AccountId"); }
  
              set { SetColumnValue("AccountId", value); }
  
          }
  
  
          [XmlAttribute("CoordinatesPerimeter")]
          public string CoordinatesPerimeter
          {
  
gt:             get { return GetColumnValue<string>("CoordinatesPerimeter"); }