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

Building an Agile SQL Data Access Layer

Rate me:
Please Sign up or sign in to vote.
4.80/5 (5 votes)
6 Jan 2009CPOL4 min read 51K   646   58  
An article on building a SQL Server data access layer in C# in a completely separate layer.
using System;
using System.Collections.Generic;
using System.Text;
using InMemoryDal.Entities;
using InMemoryDal.Interfaces;

namespace InMemoryDal.InMemoryData
{
    [Serializable]
    public sealed class CustomerInMemoryDAL : ICustomerDAL
    {
        internal List<Customer> CustomerList;

        static readonly CustomerInMemoryDAL _istance = new CustomerInMemoryDAL();

        private CustomerInMemoryDAL()
        {
            CustomerList = new List<Customer>();
        }

        internal static CustomerInMemoryDAL Istance
        {
            get { return _istance; }
        }

        #region ICustomerDAL Members

        public List<Customer> Search(Guid id, String firstname, String lastname, String address, CustomerDataAdapterHandler customerDataAdapter)
        {
            List<Customer> lis = CustomerList;

            if (firstname != String.Empty) { lis = lis.FindAll(delegate(Customer entity) { return entity.Firstname == firstname; }); }

            if (id != Guid.Empty) { lis = lis.FindAll(delegate(Customer entity) { return entity.Id == id; }); }

            if (lastname != String.Empty) { lis = lis.FindAll(delegate(Customer entity) { return entity.Lastname == lastname; }); }

            if (address != String.Empty) { lis = lis.FindAll(delegate(Customer entity) { return entity.Address == address; }); }



            return lis;
        }

        #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)


Written By
Italy Italy
Software architect. At present working on C# development, with mainly Asp.net Ajax and MVC user inteface. Particularly interested in OOP, test driven, agile development.

Comments and Discussions