예제 #1
0
        /// <summary>
        /// Удаление модели данных командой
        /// </summary>
        /// <returns></returns>
        public virtual Exception Delete()
        {
            object keyValue = GetProperty <object>(SchemaTableManager.GetPrimaryKeyField(this.GetType()));

            if (_dataAdapter != null && _dataAdapter.DeleteCommand != null)
            {
                UniDbCommand deleteCmd = new UniDbCommand(_dataAdapter.DeleteCommand.CommandText, this.Connection);
                if (_dataAdapter.DeleteCommand.Parameters.Count > 0)
                {
                    UniParameter p = _dataAdapter.DeleteCommand.Parameters[0];
                    deleteCmd.Parameters.Add(p.ParameterName, p.UniDbType, keyValue);
                }
                else
                {
                    deleteCmd.Parameters.Add("p_" + SchemaTableManager.GetPrimaryKeyField(this.GetType()), UniDbType.Decimal, keyValue);
                }
                return(ExecuteDeleteCommand(deleteCmd));
            }
            else
            {
                UniDbCommand deleteCmd = UniCommandBuilder.GetDeleteCommand(SchemaTable, TableName, SchemaTableManager.GetUpdatedColumns(TableName, DataTable));
                deleteCmd.Parameters[0].Value        = keyValue;
                deleteCmd.Parameters[0].SourceColumn = string.Empty;
                return(ExecuteDeleteCommand(deleteCmd));
            }
        }
예제 #2
0
        /// <summary>
        /// Инициализация адаптера сохранения данных
        /// </summary>
        public virtual void InitializeAdapter()
        {
            _dataAdapter = new UniDbAdapter();
            UniSchemaColumn[] cols = SchemaTableManager.GetUpdatedColumns(TableName, DataTable).ToArray();
            if (cols == null)
            {
                return;
            }

            _dataAdapter.AcceptChangesDuringUpdate = false;

            _dataAdapter.InsertCommand = UniCommandBuilder.GetInsertCommand(SchemaTable, TableName, cols);
            _dataAdapter.UpdateCommand = UniCommandBuilder.GetUpdateCommand(SchemaTable, TableName, cols);
            _dataAdapter.DeleteCommand = UniCommandBuilder.GetDeleteCommand(SchemaTable, TableName, cols);
        }