コード例 #1
0
        /// <summary>
        /// Adds or sets a value for a specific column.
        /// </summary>
        /// <param name="column">The column that is going to hold the value.</param>
        /// <param name="value">The value to be inserted.</param>
        public BuiltValueList <T> AddValueFor(string column, string value)
        {
            if (_columnsWithValues.All(col => col.Column != column))
            {
                throw new Exception($"This BuiltInsertValue does not contain a column named \"{column}\"");
            }

            if (SqlTableHelper.GetColumnNames <T>().All(columnName => columnName != column))
            {
                throw new Exception($"Table \"{typeof(T).FullName}\" does not contain a column named \"{column}\"");
            }

            if (ContainsColumn(column))
            {
                var columnWithValue = _columnsWithValues.Single(col => col.Column == column);
                _columnsWithValues.Remove(columnWithValue);
                columnWithValue.Value = value;
                _columnsWithValues.Add(columnWithValue);
            }
            else
            {
                _columnsWithValues.Add(new ColumnWithValue
                {
                    Column = column,
                    Value  = value
                });
            }

            return(this);
        }
コード例 #2
0
 /// <summary>
 /// Add all columns from the specified table to be selected.
 /// </summary>
 /// <typeparam name="T">The table containing the columns.</typeparam>
 public BuiltSelectCommand AddColumns <T>()
 {
     foreach (string column in SqlTableHelper.GetColumnNames <T>())
     {
         string fullyQualified = $"{Util.FormatSQL(SqlTableHelper.GetTableName<T>(), column)}";
         if (!_selectedColumns.Contains(fullyQualified))
         {
             _selectedColumns.Add(fullyQualified);
         }
     }
     return(this);
 }
コード例 #3
0
        /// <summary>
        /// Adds a table to used in the FROM clause.
        /// </summary>
        /// <param name="tableType">The table to be added.</param>
        /// <param name="selectAllColumns">Whether all columns from this table should be added to the selection.</param>
        public BuiltSelectCommand AddTable(Type tableType, bool selectAllColumns = true)
        {
            string tableName = SqlTableHelper.GetTableName(tableType);

            _fromTables.Add(tableName);

            if (selectAllColumns)
            {
                AddColumns(tableType, SqlTableHelper.GetColumnNames(tableType).ToArray());
            }

            return(this);
        }
コード例 #4
0
 internal BuiltInsertCommand()
 {
     _rowValues = new List <BuiltValueList <T> >();
     _table     = SqlTableHelper.GetTableName <T>();
     _columns   = SqlTableHelper.GetColumnNames <T>();
 }