Tips - Create Custom Crud Class

Use the Crud class to inherit the database access methods.

// Crud | CustomDomainCrud.cs

namespace Com.Example.Labs.Crud
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;

    using Com.Example.Labs.Core;
    using Com.Example.Labs.Models;

    public class CustomDomainCrud : Crud
    {
        #region [ Constructor ]

        // Define the following contructor

        public CustomDomainCrud(IUserContext userContext)
            : base(userContext)
        {
            base.Initialize();
        }

        #endregion

        #region [ Public methods ]

        public IList<CustomDataModel> GetData()
        {
            IList<CustomDataModel> list = new List<CustomDataModel>();

            DbConnection dbConnection;

            using (var et = new ExecutionTracerService())
            using (var dbReader = base.ToDataReader("CustomDomain_Custom_GetData", null, out dbConnection))
            {
                while (dbReader.Read())
                {
                    CustomDataModel item = new CustomDataModel();

                    // Mapping...

                    item.Field1 = TypeHelper.To<int>(dbReader, "Field1");
                    item.Field2 = TypeHelper.To<string>(dbReader, "Field2");
                    item.Field3 = TypeHelper.To<double?>(dbReader, "Field3");

                    list.Add(item);
                }
            }

            if (dbConnection != null)
                dbConnection.Close();

            return list;
        }

        #endregion
    }
}

Important

To use it over Service & WCF layers do not forget to create the Business class and to generate the associated service using LayerCake Generator Process.

An example can be found in the Crud\AppCrud\CommonCrud.cs & Business\AppBusiness\CommonBusiness.cs files.