Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » ADO.NET » Downloads
 
Add your own
alternative version

Light ORM Library for .NET

, 8 Oct 2010 CPOL
This article is about the Light Object-Relational Mapping library.
using System;
using System.Data;

namespace Light
{
	/// <summary>
	/// Represents a database command parameter.
	/// </summary>
	public class Parameter
	{
		private DbType dbType = DbType.Object;
		private ParameterDirection direction = ParameterDirection.Input;
		private string parameterName = "";
		private int size = 0;
		private byte precision = 0;
		private byte scale = 0;
		private object value = null;
		private string columnName = "";
		
		/// <summary>
		/// Creates a new instance.
		/// </summary>
		public Parameter()
		{}
		
		/// <summary>
		/// Creates a new instance.
		/// </summary>
		/// <param name="dbtype">database data type</param>
		/// <param name="value">value</param>
		public Parameter(DbType dbtype, object value)
			: this(dbtype, 0, value)
		{}
		
		/// <summary>
		/// Creates a new instance.
		/// </summary>
		/// <param name="dbtype">database data type</param>
		/// <param name="size">database data type size</param>
		/// <param name="value">value</param>
		public Parameter(DbType dbtype, int size, object value)
			: this("", dbtype, size, value)
		{}
		
		/// <summary>
		/// Creates a new instance.
		/// </summary>
		/// <param name="name">parameter name</param>
		/// <param name="dbtype">database data type</param>
		public Parameter(string name, DbType dbtype)
			: this(name, dbtype, 0, null)
		{}
		
		/// <summary>
		/// Creates a new instance.
		/// </summary>
		/// <param name="name">parameter name</param>
		/// <param name="dbtype">database data type</param>
		/// <param name="value">value</param>
		public Parameter(string name, DbType dbtype, object value)
			: this(name, dbtype, 0, value)
		{}
		
		/// <summary>
		/// Creates a new instance.
		/// </summary>
		/// <param name="name">parameter name</param>
		/// <param name="dbtype">database data type</param>
		/// <param name="size">database data type size</param>
		/// <param name="value">value</param>
		public Parameter(string name, DbType dbtype, int size, object value)
		{
			parameterName = name;
			dbType = dbtype;
			this.size = size;
			this.value = value;
		}
		
		/// <summary>
		/// Gets or sets data type.
		/// </summary>
		public DbType DBType
		{
			get { return dbType; }
			set { dbType = value; }
		}
		
		/// <summary>
		/// Gets or sets parameter direction.
		/// </summary>
		public ParameterDirection Direction
		{
			get { return direction; }
			set { direction = value; }
		}
		
		/// <summary>
		/// Gets or sets parameter name.
		/// </summary>
		public string ParameterName
		{
			get { return parameterName; }
			set { parameterName = value; }
		}
		
		/// <summary>
		/// Gets or sets parameter data size.
		/// </summary>
		public int Size
		{
			get { return size; }
			set { size = value; }
		}
		
		/// <summary>
		/// Gets or sets data precision.
		/// </summary>
		public byte Precision
		{
			get { return precision; }
			set { precision = value; }
		}
		
		/// <summary>
		/// Gets or sets data scale.
		/// </summary>
		public byte Scale
		{
			get { return scale; }
			set { scale = value; }
		}
		
		/// <summary>
		/// Gets or sets parameter value.
		/// </summary>
		public object Value
		{
			get { return value; }
			set { this.value = value; }
		}
		
		/// <summary>
		/// Gets or sets the column name from which this
		/// parameter was created.
		/// </summary>
		internal string ColumnName
		{
			get { return columnName; }
			set { columnName = value; }
		}
		
		#region - Chaining methods -
		/// <summary>
		/// Sets the name of this parameter.
		/// </summary>
		/// <param name="name">name to set</param>
		/// <returns>this parameter</returns>
		public Parameter SetName(string name)
		{
			parameterName = name;
			return this;
		}
		
		/// <summary>
		/// Sets the db type of this parameter.
		/// </summary>
		/// <param name="type">db type to set</param>
		/// <returns>this parameter</returns>
		public Parameter SetDBType(DbType type)
		{
			dbType = type;
			return this;
		}
		
		/// <summary>
		/// Sets the size of this parameter.
		/// </summary>
		/// <param name="size">size to set</param>
		/// <returns>this parameter</returns>
		public Parameter SetSize(int size)
		{
			this.size = size;
			return this;
		}
		
		/// <summary>
		/// Sets the direction of this parameter.
		/// </summary>
		/// <param name="dir">direction to set</param>
		/// <returns>this parameter</returns>
		public Parameter SetDirection(ParameterDirection dir)
		{
			direction = dir;
			return this;
		}
		
		/// <summary>
		/// Sets the precision of this parameter.
		/// </summary>
		/// <param name="precision">precision to set</param>
		/// <returns>this parameter</returns>
		public Parameter SetPrecision(byte precision)
		{
			this.precision = precision;
			return this;
		}
		
		/// <summary>
		/// Sets the scale of this parameter.
		/// </summary>
		/// <param name="scale">scale to set</param>
		/// <returns>this parameter</returns>
		public Parameter SetScale(byte scale)
		{
			this.scale = scale;
			return this;
		}
		
		/// <summary>
		/// Sets the value of this parameter.
		/// </summary>
		/// <param name="value">value to set</param>
		/// <returns>this parameter</returns>
		public Parameter SetValue(object value)
		{
			this.value = value;
			return this;
		}
		
		/// <summary>
		/// Sets the name of the columns from which this parameter was generated
		/// by Light framework.
		/// </summary>
		/// <param name="name">column name</param>
		/// <returns>this parameter</returns>
		internal Parameter SetColumnName(string name)
		{
			this.columnName = name;
			return this;
		}
		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sergey Busel
Software Developer (Senior)
United States United States
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141220.1 | Last Updated 8 Oct 2010
Article Copyright 2007 by Sergey Busel
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid