public void Delete([NotNull] IBaseDataItem dataItem)
        {
            if (!dataItem.DeleteStoredProcedure.IsAssigned())
            {
                throw new Exception("DeleteStoredProcedure not generated/installed");
            }

            _repository.ExecuteDeleteStoredProcedure(dataItem);
        }
        public void GetItemBy([NotNull] IBaseDataItem dataItem, string storedProcedure)
        {
            if (!storedProcedure.IsAssigned())
            {
                throw new Exception("GetStoredProcedure not generated/installed");
            }

            _repository.ExecuteGetByStoredProcedure(dataItem, storedProcedure);
        }
        public void ExecuteSaveStoredProcedure([NotNull] IBaseDataItem dataItem)
        {
            var database = GetDatabase();

            using (var dbCommand = database.GetStoredProcCommand(dataItem.SaveStoredProcedure))
            {
                SetParameterData(dataItem, database, dbCommand);

                database.ExecuteNonQuery(dbCommand);

                GetParameterData(dataItem, database, dbCommand);
            }
        }
        public void Save([NotNull] IBaseDataItem dataItem)
        {
            if (dataItem.AutoIdField.Equals(string.Empty))
            {
                throw new Exception("AutoIdField not generated");
            }

            if (dataItem.SaveStoredProcedure.Equals(string.Empty))
            {
                throw new Exception("SaveStoredProcedure not generated/installed");
            }

            _repository.ExecuteSaveStoredProcedure(dataItem);
        }
        public void ExecuteGetStoredProcedure([NotNull] IBaseDataItem dataItem)
        {
            var database = GetDatabase();

            using (var dbCommand = database.GetStoredProcCommand(dataItem.GetStoredProcedure))
            {
                SetParameterData(dataItem.GetParameterObjects(), database, dbCommand);

                using (var dataReader = database.ExecuteReader(dbCommand))
                {
                    if (dataReader.Read())
                    {
                        dataItem.GetKey(dataReader);
                        dataItem.GetData(dataReader);
                    }
                }
            }
        }
        private static void GetParameterData([NotNull] IBaseDataItem dataItem, [NotNull] Database database, DbCommand dbCommand)
        {
            dataItem.SetId((int)database.GetParameterValue(dbCommand, dataItem.AutoIdField));

            foreach (var kvp in dataItem.AutoUpdateFieldDictionary)
            {
                var fieldValue = database.GetParameterValue(dbCommand, kvp.Value.ParameterName);

                if (DBNull.Value.Equals(fieldValue))
                {
                    kvp.Value.Value = null;

                    continue;
                }

                kvp.Value.Value = fieldValue;
            }
        }
        public void ExecuteDeleteStoredProcedure([NotNull] IBaseDataItem dataItem)
        {
            var id = dataItem.GetId();

            if (id == 0)
            {
                return;
            }

            var database = GetDatabase();

            using (var dbCommand = database.GetStoredProcCommand(dataItem.DeleteStoredProcedure))
            {
                database.AddInParameter(dbCommand, dataItem.AutoIdField, DbType.Int32, dataItem.GetId());

                database.ExecuteNonQuery(dbCommand);
            }
        }
        private static void SetParameterData([NotNull] IBaseDataItem dataItem, [NotNull] Database database, DbCommand dbCommand)
        {
            // autoidfield
            database.AddParameter(dbCommand, dataItem.AutoIdField, DbType.Int32, ParameterDirection.InputOutput,
                                  dataItem.AutoIdField, DataRowVersion.Proposed, dataItem.GetId());

            // fields changing at the database side
            foreach (var parameterObject in dataItem.AutoUpdateFieldDictionary.Values)
            {
                database.AddParameter(dbCommand, parameterObject.ParameterName, parameterObject.DbType, ParameterDirection.InputOutput,
                                      parameterObject.ParameterName, DataRowVersion.Proposed, parameterObject.Value);
            }

            // all the other fields
            foreach (var parameterObject in dataItem.SetItemData())
            {
                database.AddInParameter(dbCommand, parameterObject.ParameterName, parameterObject.DbType, parameterObject.Value);
            }
        }