Click here to Skip to main content
15,891,431 members
Articles / Programming Languages / C#

Design and Implementation of an Attribute-Driven, Caching Data Abstraction Layer

Rate me:
Please Sign up or sign in to vote.
4.98/5 (25 votes)
21 Jul 2008CPOL30 min read 68.7K   595   103  
An easy-to-use, attribute-driven data abstraction layer with multi-database support, intelligent caching, transparent encryption, multi-property sorting, property change tracking, etc.
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Forms;
using System.Windows;
using System.Threading;
using System.Reflection;
using System.Diagnostics;
using System.Text;
using System.Net;
using System.IO;
using System.Data;
using System.Data.Common;
using BrainTechLLC.DAL;

namespace DALSampleApplication
{
	/// <summary>
	/// Demonstrates reading a connection string from the ConnectionStrings section of app.config or web.config
	/// </summary>
	[TableName("UserInfo"), CollectionCacheable, PrepopulateCache(false)]
	[DataTransportType(DataTransport.SqlDirectConnection), IDALDatabaseClassName("DALSqlServer")]
	[ReadConnectionStringFromConnectionStringKey("DBConnectionString")]
	public partial class UserInfo : DBLayer<UserInfo>, IDBLayer<UserInfo>, INotifyPropertyChanged
	{
		private long _user_id;
		private string _login_name = String.Empty;
		private string _password = String.Empty;

		[MappedToColumn, Identity, PrimaryKey, QuickLookup]
		public long user_id
		{
			get { return _user_id; }
			set { Set<long>(ref _user_id, "user_id", value); }
		}

		[MappedToColumn("login_name"), LimitTextLength(50)]
		public string login_name
		{
			get { return _login_name; }
			set { SetString(ref _login_name, "login_name", value); }
		}

		[MappedToColumn("password"), LimitTextLength(50)]
		public string password
		{
			get { return _password; }
			set { SetString(ref _password, "password", value); }
		}

		public static DALColumn<long> Col_user_id { get { return new DALColumn<long>("user_id"); } }
		public static DALColumn<string> Col_login_name { get { return new DALColumn<string>("login_name"); } }
		public static DALColumn<string> Col_password { get { return new DALColumn<string>("password"); } }
	}
}


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) Troppus Software
United States United States
Currently working as a Senior Silverlight Developer with Troppus Software in Superior, CO. I enjoy statistics, programming, new technology, playing the cello, and reading codeproject articles. Smile | :)

Comments and Discussions