⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _categories.cs

📁 EasyObjects 是ORM的典型应用的例子是学习研究的很好的范例
💻 CS
📖 第 1 页 / 共 2 页
字号:
/*
'===============================================================================
'  Generated From - CSharp_EasyObject_BusinessEntity.vbgen
' 
'  ** IMPORTANT  ** 
'  How to Generate your stored procedures:
' 
'  SQL      = SQL_DAAB_StoredProcs.vbgen
'  
'  This object is 'abstract' which means you need to inherit from it to be able
'  to instantiate it.  This is very easily done. You can override properties and
'  methods in your derived class, this allows you to regenerate this class at any
'  time and not worry about overwriting custom code. 
'
'  NEVER EDIT THIS FILE.
'
'  public class YourObject :  _YourObject
'  {
'
'  }
'
'===============================================================================
*/

// Generated by MyGeneration Version # (1.2.0.2)

using System;
using System.Data;
using System.Data.Common;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
using System.IO;

using Microsoft.Practices.EnterpriseLibrary.Data;
using NCI.EasyObjects;

namespace EasyObjectsQuickStart.BLL
{

	#region Schema

	public class CategoriesSchema : NCI.EasyObjects.Schema
	{
		private static ArrayList _entries;
		public static SchemaItem CategoryID = new SchemaItem("CategoryID", DbType.Int32, true, false, false, true, true, false);
		public static SchemaItem CategoryName = new SchemaItem("CategoryName", DbType.String, SchemaItemJustify.None, 15, false, false, false, false);
		public static SchemaItem Description = new SchemaItem("Description", DbType.String, SchemaItemJustify.None, 1073741823, true, false, false, false);
		public static SchemaItem Picture = new SchemaItem("Picture", DbType.Binary, false, true, false, false, false, false);

		public override ArrayList SchemaEntries
		{
			get
			{
				if (_entries == null )
				{
					_entries = new ArrayList();
					_entries.Add(CategoriesSchema.CategoryID);
					_entries.Add(CategoriesSchema.CategoryName);
					_entries.Add(CategoriesSchema.Description);
					_entries.Add(CategoriesSchema.Picture);
				}
				return _entries;
			}
		}
		
		public static bool HasAutoKey 
		{
			get { return true;	}
		}

		public static bool HasRowID 
		{
			get { return false;	}
		}
	}
	#endregion

	public abstract class _Categories : EasyObject
	{

		public _Categories()
		{
			CategoriesSchema _schema = new CategoriesSchema();
			this.SchemaEntries = _schema.SchemaEntries;
			this.SchemaGlobal = "dbo";
		}
		
		public override void FlushData() 	 
		{ 	 
			this._whereClause = null; 	 
			this._aggregateClause = null; 	 
			base.FlushData(); 	 
		}
			   
		/// <summary>
		/// Loads the business object with info from the database, based on the requested primary key.
		/// </summary>
		/// <param name="CategoryID"></param>
		/// <returns>A Boolean indicating success or failure of the query</returns>
		public bool LoadByPrimaryKey(int CategoryID)
		{
			switch(this.DefaultCommandType)
			{
				case CommandType.StoredProcedure:
					ListDictionary parameters = new ListDictionary();

					// Add in parameters
					parameters.Add(CategoriesSchema.CategoryID.FieldName, CategoryID);

					return base.LoadFromSql(this.SchemaStoredProcedureWithSeparator + "daab_GetCategories", parameters, CommandType.StoredProcedure);

				case CommandType.Text:
					this.Query.ClearAll();
					this.Where.WhereClauseReset();
					this.Where.CategoryID.Value = CategoryID;
					return this.Query.Load();

				default:
					throw new ArgumentException("Invalid CommandType", "commandType");
			}
		}
	
		/// <summary>
		/// Loads all records from the table.
		/// </summary>
		/// <returns>A Boolean indicating success or failure of the query</returns>
		public bool LoadAll()
		{
			switch(this.DefaultCommandType)
			{
				case CommandType.StoredProcedure:
					return base.LoadFromSql(this.SchemaStoredProcedureWithSeparator + "daab_GetAllCategories", null, CommandType.StoredProcedure);

				case CommandType.Text:
					this.Query.ClearAll();
					this.Where.WhereClauseReset();
					return this.Query.Load();

				default:
					throw new ArgumentException("Invalid CommandType", "commandType");
			}
		}

		/// <summary>
		/// Adds a new record to the internal table.
		/// </summary>
		public override void AddNew()
		{
			base.AddNew();
			this.ApplyDefaults();
		}

		/// <summary>
		/// Apply any default values to columns
		/// </summary>
		protected override void ApplyDefaults()
		{
		}

		protected override DbCommand GetInsertCommand(CommandType commandType)
		{	
			DbCommand dbCommand;

			// Create the Database object, using the default database service. The
			// default database service is determined through configuration.
			Database db = GetDatabase();

			switch(commandType)
			{
				case CommandType.StoredProcedure:
					string sqlCommand = this.SchemaStoredProcedureWithSeparator + "daab_AddCategories";
					dbCommand = db.GetStoredProcCommand(sqlCommand);

					db.AddParameter(dbCommand, "CategoryID", DbType.Int32, 0, ParameterDirection.Output, true, 0, 0, "CategoryID", DataRowVersion.Default, Convert.DBNull);
					CreateParameters(db, dbCommand);
					
					return dbCommand;

				case CommandType.Text:
					this.Query.ClearAll();
					this.Where.WhereClauseReset();
					foreach(SchemaItem item in this.SchemaEntries)
					{
						if (!item.IsComputed)
						{
							if ((item.IsAutoKey && this.IdentityInsert) || !item.IsAutoKey)
							{
								this.Query.AddInsertColumn(item);
							}
						}
					}
					dbCommand = this.Query.GetInsertCommandWrapper();

					dbCommand.Parameters.Clear();
					if (this.IdentityInsert)
					{
						db.AddInParameter(dbCommand, "CategoryID", DbType.Int32, "CategoryID", DataRowVersion.Default);
					}
					else
					{
						db.AddParameter(dbCommand, "CategoryID", DbType.Int32, 0, ParameterDirection.Output, true, 0, 0, "CategoryID", DataRowVersion.Default, Convert.DBNull);
					}
					CreateParameters(db, dbCommand);

					return dbCommand;

				default:
					throw new ArgumentException("Invalid CommandType", "commandType");
			}
		}

		protected override DbCommand GetUpdateCommand(CommandType commandType)
		{
            DbCommand dbCommand;

			// Create the Database object, using the default database service. The
			// default database service is determined through configuration.
			Database db = GetDatabase();

			switch(commandType)
			{
				case CommandType.StoredProcedure:
					string sqlCommand = this.SchemaStoredProcedureWithSeparator + "daab_UpdateCategories";
					dbCommand = db.GetStoredProcCommand(sqlCommand);

					db.AddInParameter(dbCommand, "CategoryID", DbType.Int32, "CategoryID", DataRowVersion.Current);
					CreateParameters(db, dbCommand);
					
					return dbCommand;

				case CommandType.Text:
					this.Query.ClearAll();
					foreach(SchemaItem item in this.SchemaEntries)
					{
						if (!(item.IsAutoKey || item.IsComputed))
						{
							this.Query.AddUpdateColumn(item);
						}
					}

					this.Where.WhereClauseReset();
					this.Where.CategoryID.Operator = WhereParameter.Operand.Equal;
					dbCommand = this.Query.GetUpdateCommandWrapper();

					dbCommand.Parameters.Clear();
					CreateParameters(db, dbCommand);
					db.AddInParameter(dbCommand, "CategoryID", DbType.Int32, "CategoryID", DataRowVersion.Current);
					
					return dbCommand;

				default:
					throw new ArgumentException("Invalid CommandType", "commandType");
			}
		}

		protected override DbCommand GetDeleteCommand(CommandType commandType)
		{
            DbCommand dbCommand;

			// Create the Database object, using the default database service. The
			// default database service is determined through configuration.
			Database db = GetDatabase();

			switch(commandType)
			{
				case CommandType.StoredProcedure:
					string sqlCommand = this.SchemaStoredProcedureWithSeparator + "daab_DeleteCategories";
					dbCommand = db.GetStoredProcCommand(sqlCommand);
					db.AddInParameter(dbCommand, "CategoryID", DbType.Int32, "CategoryID", DataRowVersion.Current);
					
					return dbCommand;

				case CommandType.Text:
					this.Query.ClearAll();
					this.Where.WhereClauseReset();
					this.Where.CategoryID.Operator = WhereParameter.Operand.Equal;
					dbCommand = this.Query.GetDeleteCommandWrapper();

					dbCommand.Parameters.Clear();
					db.AddInParameter(dbCommand, "CategoryID", DbType.Int32, "CategoryID", DataRowVersion.Current);
					
					return dbCommand;

				default:
					throw new ArgumentException("Invalid CommandType", "commandType");
			}
		}

		private void CreateParameters(Database db, DbCommand dbCommand)
		{
			db.AddInParameter(dbCommand, "CategoryName", DbType.String, "CategoryName", DataRowVersion.Current);
			db.AddInParameter(dbCommand, "Description", DbType.String, "Description", DataRowVersion.Current);
			db.AddInParameter(dbCommand, "Picture", DbType.Binary, "Picture", DataRowVersion.Current);
		}
		
		#region Properties
		public virtual int CategoryID
		{
			get
			{
				return this.GetInteger(CategoriesSchema.CategoryID.FieldName);
	    	}
			set
			{
				this.SetInteger(CategoriesSchema.CategoryID.FieldName, value);
			}
		}
		public virtual string CategoryName
		{
			get
			{
				return this.GetString(CategoriesSchema.CategoryName.FieldName);
	    	}
			set
			{
				this.SetString(CategoriesSchema.CategoryName.FieldName, value);
			}
		}
		public virtual string Description
		{
			get
			{
				return this.GetString(CategoriesSchema.Description.FieldName);
	    	}
			set
			{
				this.SetString(CategoriesSchema.Description.FieldName, value);
			}
		}
		public virtual byte[] Picture
		{
			get
			{
				return this.GetByteArray(CategoriesSchema.Picture.FieldName);
	    	}
			set
			{
				this.SetByteArray(CategoriesSchema.Picture.FieldName, value);
			}
		}

		public override string TableName
		{
			get { return "Categories"; }
		}
		
		#endregion		
		
		#region String Properties
		public virtual string s_CategoryID
		{
			get
			{
			    return this.IsColumnNull(CategoriesSchema.CategoryID.FieldName) ? string.Empty : base.GetIntegerAsString(CategoriesSchema.CategoryID.FieldName);
			}
			set
			{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -