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 LanguageAccountMap class.
	/// </summary>
	[Serializable]
	public partial class LanguageAccountMapCollection : ActiveList<LanguageAccountMap, LanguageAccountMapCollection> 
	{	   
		public LanguageAccountMapCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the LanguageAccountMap table.
	/// </summary>
	[Serializable]
	public partial class LanguageAccountMap : ActiveRecord<LanguageAccountMap>
	{
		#region .ctors and Default Settings
		
		public LanguageAccountMap()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public LanguageAccountMap(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public LanguageAccountMap(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public LanguageAccountMap(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("LanguageAccountMap", TableType.Table, DataService.GetInstance("CMS"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarLanguageAccountMapId = new TableSchema.TableColumn(schema);
				colvarLanguageAccountMapId.ColumnName = "LanguageAccountMapId";
				colvarLanguageAccountMapId.DataType = DbType.Int32;
				colvarLanguageAccountMapId.MaxLength = 0;
				colvarLanguageAccountMapId.AutoIncrement = true;
				colvarLanguageAccountMapId.IsNullable = false;
				colvarLanguageAccountMapId.IsPrimaryKey = true;
				colvarLanguageAccountMapId.IsForeignKey = false;
				colvarLanguageAccountMapId.IsReadOnly = false;
				colvarLanguageAccountMapId.DefaultSetting = @"";
				colvarLanguageAccountMapId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLanguageAccountMapId);
				
				TableSchema.TableColumn colvarLanguageId = new TableSchema.TableColumn(schema);
				colvarLanguageId.ColumnName = "LanguageId";
				colvarLanguageId.DataType = DbType.Int32;
				colvarLanguageId.MaxLength = 0;
				colvarLanguageId.AutoIncrement = false;
				colvarLanguageId.IsNullable = false;
				colvarLanguageId.IsPrimaryKey = false;
				colvarLanguageId.IsForeignKey = true;
				colvarLanguageId.IsReadOnly = false;
				colvarLanguageId.DefaultSetting = @"";
				
					colvarLanguageId.ForeignKeyTableName = "Language";
				schema.Columns.Add(colvarLanguageId);
				
				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);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["CMS"].AddSchema("LanguageAccountMap",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("LanguageAccountMapId")]
		public int LanguageAccountMapId 
		{
			get { return GetColumnValue<int>("LanguageAccountMapId"); }

			set { SetColumnValue("LanguageAccountMapId", value); }

		}

		  
		[XmlAttribute("LanguageId")]
		public int LanguageId 
		{
			get { return GetColumnValue<int>("LanguageId"); }

			set { SetColumnValue("LanguageId", value); }

		}

		  
		[XmlAttribute("AccountId")]
		public int AccountId 
		{
			get { return GetColumnValue<int>("AccountId"); }

			set { SetColumnValue("AccountId", value); }

		}

		
		#endregion
		
		
			
		
		#region ForeignKey Properties
		
		/// <summary>
		/// Returns a Account ActiveRecord object related to this LanguageAccountMap
		/// 
		/// </summary>
		public CMS.Account Account
		{
			get { return CMS.Account.FetchByID(this.AccountId); }

			set { SetColumnValue("AccountId", value.AccountId); }

		}

		
		
		/// <summary>
		/// Returns a Language ActiveRecord object related to this LanguageAccountMap
		/// 
		/// </summary>
		public CMS.Language Language
		{
			get { return CMS.Language.FetchByID(this.LanguageId); }

			set { SetColumnValue("LanguageId", value.LanguageId); }

		}

		
		
		#endregion
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int varLanguageId,int varAccountId)
		{
			LanguageAccountMap item = new LanguageAccountMap();
			
			item.LanguageId = varLanguageId;
			
			item.AccountId = varAccountId;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varLanguageAccountMapId,int varLanguageId,int varAccountId)
		{
			LanguageAccountMap item = new LanguageAccountMap();
			
				item.LanguageAccountMapId = varLanguageAccountMapId;
				
				item.LanguageId = varLanguageId;
				
				item.AccountId = varAccountId;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string LanguageAccountMapId = @"LanguageAccountMapId";
			 public static string LanguageId = @"LanguageId";
			 public static string AccountId = @"AccountId";
						
		}

		#endregion
	}

}

