//"Insert" method to directly save objects with composite keys
        public virtual int Add(T type, bool validateEntity = false, string endPoint = "", string transID = "")
        {
            //var compositeKeys = typeof(T).GetProperties().Any(p => p.GetCustomAttributes(typeof(CompositeKeyColumnAttribute), true).Length != 0);
            //var identityPropertyName = typeof(T).GetProperties().SingleOrDefault(t => t.Name.ToLower().StartsWith("id")) == null ? "ID"
            //   : typeof(T).GetProperties().SingleOrDefault(t => t.Name.ToLower().StartsWith("id")).Name;
            //var id = Convert.ToInt32(typeof(T).GetProperty(identityPropertyName).GetValue(type, null));
            //var v = id > 0 && !compositeKeys ? _repository.Single<T>(id) : null;

            if (validateEntity)
            {
                var validator = new Validation.EntityValidator <T>();
                var vr        = validator.Validate(type);

                if (vr.HasError)
                {
                    throw new Exception("Validation: " + vr.ErrorList);
                }
            }
            try
            {
                if (!string.IsNullOrEmpty(endPoint) && !string.IsNullOrEmpty(transID) && typeof(T).Name != "Audit")
                {
                    /*Auditor.Add<T>(new Auditor.AuditAction
                     * {
                     *  Endpoint = endPoint,
                     *  Operation = "insert",
                     *  TransactionID = transID,
                     * }, type, type, "id", "created");*/
                }

                var result = _repository.Insert(type);
                return((result == null || result.Equals(0)) ? 0 : Convert.ToInt32(result));
            }
            catch (SqlException sx)
            {
                throw new Exception(new ValidationExceptionParser(TableName, sx).ValidationErrorMessage, sx);
            }
            finally
            {
                _repository.Dispose();
            }
        }
        public virtual int Update(T type, bool validateEntity = false)
        {
            var identityPropertyName = typeof(T).GetProperties().SingleOrDefault(t => t.Name.ToLower().StartsWith("id")) == null
                ? "ID"
                : typeof(T).GetProperties().SingleOrDefault(t => t.Name.ToLower().StartsWith("id")).Name;

            var id = Convert.ToInt32(typeof(T).GetProperty(identityPropertyName).GetValue(type, null));

            if (id == 0)
            {
                return(Save(type, validateEntity));
            }

            if (validateEntity)
            {
                var validator = new Validation.EntityValidator <T>();
                var vr        = validator.Validate(type);

                if (vr.HasError)
                {
                    throw new Exception("Validation: " + vr.ErrorList);
                }
            }
            try
            {
                var result = _repository.Update(type, id);
                return((result == null || result.Equals(0)) ? 0 : id);
            }
            catch (SqlException sx)
            {
                throw new Exception(new ValidationExceptionParser(TableName, sx).ValidationErrorMessage, sx);
            }
            finally
            {
                _repository.Dispose();
            }
        }