Click here to Skip to main content
15,892,298 members
Articles / Database Development / SQL Server

Light ORM Library for .NET

Rate me:
Please Sign up or sign in to vote.
4.83/5 (39 votes)
8 Oct 2010CPOL17 min read 222.4K   3.1K   184  
This article is about the Light Object-Relational Mapping library.
using System;
using System.Data;

namespace Light
{
	/// <summary>
	/// Marks a property or a field as a column.
	/// </summary>
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field,
					Inherited=false, AllowMultiple=false)]
	public class ColumnAttribute : Attribute
	{
		private string name;
		private DbType dbtype;
		private int size;
		private byte precision;
		private byte scale;
		private bool primaryKey;
		private bool autoIncrement;
		
		/// <summary>
		/// Marks a property or a field as a column.
		/// </summary>
		public ColumnAttribute() : this("")
		{
		}
		
		/// <summary>
		/// Marks a property or a field as a column.
		/// </summary>
		/// <param name="name">column name</param>
		public ColumnAttribute(string name)
			: this(name, DbType.Object)
		{
		}
		
		/// <summary>
		/// Marks a property or a field as a column.
		/// </summary>
		/// <param name="dbtype">database data type</param>
		public ColumnAttribute(DbType dbtype) : this("", dbtype)
		{
		}
		
		/// <summary>
		/// Marks a property or a field as a column.
		/// </summary>
		/// <param name="name">column name</param>
		/// <param name="dbtype">database data type</param>
		public ColumnAttribute(string name, DbType dbtype)
			: this(name, dbtype, 0)
		{
		}
		
		/// <summary>
		/// Marks a property or a field as a column.
		/// </summary>
		/// <param name="dbtype">database data type</param>
		/// <param name="size">database data type size</param>
		public ColumnAttribute(DbType dbtype, int size)
			: this("", dbtype, size)
		{
		}
		
		/// <summary>
		/// Marks a property or a field as a column.
		/// </summary>
		/// <param name="name">column name</param>
		/// <param name="dbtype">database data type</param>
		/// <param name="size">database data type size</param>
		public ColumnAttribute(string name, DbType dbtype, int size)
			: base()
		{
			this.name = name;
			this.dbtype = dbtype;
			this.size = size;
		}
		
		/// <summary>
		/// Gets or sets the name of this column.
		/// </summary>
		public string Name
		{
			get { return name; }
			set { name = value; }
		}
		
		/// <summary>
		/// Gets the database data type of this column.
		/// </summary>
		public DbType DBType
		{
			get { return dbtype; }
			set { dbtype = value; }
		}
		
		/// <summary>
		/// Gets or sets the size of the database data type.
		/// </summary>
		public int Size
		{
			get { return size; }
			set { size = value; }
		}
		
		/// <summary>
		/// Gets or sets the precision of the database data type.
		/// </summary>
		public byte Precision
		{
			get { return precision; }
			set { precision = value; }
		}
		
		/// <summary>
		/// Gets or sets the scale of the database data type.
		/// </summary>
		public byte Scale
		{
			get { return scale; }
			set { scale = value; }
		}
		
		/// <summary>
		/// Gets or sets whether this column is a primary key column.
		/// </summary>
		public bool PrimaryKey
		{
			get { return primaryKey; }
			set { primaryKey = value; }
		}
		
		/// <summary>
		/// Gets or sets whether this column is an auto incrementing column.
		/// </summary>
		public bool AutoIncrement
		{
			get { return autoIncrement; }
			set { autoIncrement = value; }
		}
	}
}

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)


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions