本文整理汇总了C#中FluentMigrator.Expressions.DeleteColumnExpression类的典型用法代码示例。如果您正苦于以下问题:C# DeleteColumnExpression类的具体用法?C# DeleteColumnExpression怎么用?C# DeleteColumnExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DeleteColumnExpression类属于FluentMigrator.Expressions命名空间,在下文中一共展示了DeleteColumnExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
public override string Generate(DeleteColumnExpression expression)
{
// before we drop a column, we have to drop any default value constraints in SQL Server
const string sql = @"
DECLARE @default sysname, @sql nvarchar(max);
-- get name of default constraint
SELECT @default = name
FROM sys.default_constraints
WHERE parent_object_id = object_id('{0}')
AND type = 'D'
AND parent_column_id = (
SELECT column_id
FROM sys.columns
WHERE object_id = object_id('{0}')
AND name = '{1}'
);
-- create alter table command as string and run it
SET @sql = N'ALTER TABLE {0} DROP CONSTRAINT ' + @default;
EXEC sp_executesql @sql;
-- now we can finally drop column
ALTER TABLE {0} DROP COLUMN {1};";
return String.Format(sql, Quoter.QuoteTableName(expression.TableName), Quoter.QuoteColumnName(expression.ColumnName));
}
示例2: Generate
public override string Generate(DeleteColumnExpression expression)
{
if (expression.ColumnNames.Count != 1)
{
throw new DatabaseOperationNotSupportedException();
}
// Limited functionality in CE, for now will just drop the column.. no DECLARE support!
const string sql = @"ALTER TABLE {0} DROP COLUMN {1};";
return String.Format(sql, Quoter.QuoteTableName(expression.TableName), Quoter.QuoteColumnName(expression.ColumnNames.ElementAt(0)));
}
示例3: Generate
public override string Generate(DeleteColumnExpression expression)
{
StringBuilder builder = new StringBuilder();
foreach (string columnName in expression.ColumnNames) {
if (expression.ColumnNames.First() != columnName) builder.AppendLine(";");
builder.AppendFormat("ALTER TABLE {0}.{1} DROP COLUMN {2}",
Quoter.QuoteSchemaName(expression.SchemaName),
Quoter.QuoteTableName(expression.TableName),
Quoter.QuoteColumnName(columnName));
}
return builder.ToString();
}
示例4: Process
public override void Process(DeleteColumnExpression expression)
{
var tableDefinition = GetTableSchema(expression.TableName);
var columnDefinitions = tableDefinition.Columns.ToList();
var indexDefinitions = tableDefinition.Indexes.ToList();
var columnsToRemove = expression.ColumnNames.ToList();
columnDefinitions.RemoveAll(c => columnsToRemove.Remove(c.Name));
indexDefinitions.RemoveAll(i => i.Columns.Any(c => expression.ColumnNames.Contains(c.Name)));
tableDefinition.Columns = columnDefinitions;
tableDefinition.Indexes = indexDefinitions;
if (columnsToRemove.Any())
{
throw new ApplicationException(string.Format("Column {0} does not exist on table {1}.", columnsToRemove.First(), expression.TableName));
}
ProcessAlterTable(tableDefinition);
}
示例5: CanDeleteColumn
public void CanDeleteColumn()
{
DeleteColumnExpression expression = new DeleteColumnExpression { TableName = table, ColumnName = column };
string sql = generator.Generate(expression);
sql.ShouldBe(string.Format("ALTER TABLE [{0}] DROP COLUMN {1}", table, column));
}
示例6: Generate
public override string Generate(DeleteColumnExpression expression)
{
// before we drop a column, we have to drop any default value constraints in SQL Server
var builder = new StringBuilder();
foreach (string column in expression.ColumnNames)
{
if (expression.ColumnNames.First() != column) builder.AppendLine("GO");
BuildDelete(expression, column, builder);
}
return builder.ToString();
}
示例7: BuildDelete
protected virtual void BuildDelete(DeleteColumnExpression expression, string columnName, StringBuilder builder)
{
builder.AppendLine(Generate(new DeleteDefaultConstraintExpression {
ColumnName = columnName,
SchemaName = expression.SchemaName,
TableName = expression.TableName
}));
builder.AppendLine();
builder.AppendLine(String.Format("-- now we can finally drop column\r\nALTER TABLE {0} DROP COLUMN {1};",
Quoter.QuoteTableName(expression.TableName),
Quoter.QuoteColumnName(columnName)));
}
示例8: Generate
public override string Generate(DeleteColumnExpression expression)
{
return string.Format("ALTER TABLE {0}.{1} DROP COLUMN {2}", FormatSchema(expression.SchemaName), FormatIdentifier(expression.TableName), FormatIdentifier(expression.ColumnName));
}
示例9: Generate
public override string Generate(DeleteColumnExpression expression)
{
// Limited functionality in CE, for now will just drop the column.. no DECLARE support!
const string sql = @"ALTER TABLE {0} DROP COLUMN {1};";
return String.Format(sql, Quoter.QuoteTableName(expression.TableName), Quoter.QuoteColumnName(expression.ColumnName));
}
示例10: ErrorIsReturnedWhenTableNameIsNull
public void ErrorIsReturnedWhenTableNameIsNull()
{
var expression = new DeleteColumnExpression { TableName = null };
var errors = ValidationHelper.CollectErrors(expression);
errors.ShouldContain(ErrorMessages.TableNameCannotBeNullOrEmpty);
}
示例11: Generate
public override string Generate(DeleteColumnExpression expression)
{
truncator.Truncate(expression);
return base.Generate(expression);
}
示例12: Column
public IDeleteColumnFromTableSyntax Column(string columnName)
{
var expression = new DeleteColumnExpression { ColumnName = columnName };
_context.Expressions.Add(expression);
return new DeleteColumnExpressionBuilder(expression);
}
示例13: ErrorIsNotReturnedWhenTableNameIsNotNullEmptyString
public void ErrorIsNotReturnedWhenTableNameIsNotNullEmptyString()
{
var expression = new DeleteColumnExpression { TableName = "Bacon" };
var errors = ValidationHelper.CollectErrors(expression);
errors.ShouldNotContain(ErrorMessages.TableNameCannotBeNullOrEmpty);
}
示例14: CanDropMultipleColumns
public void CanDropMultipleColumns()
{
var expression = new DeleteColumnExpression();
expression.TableName = "NewTable";
expression.ColumnNames.Add("NewColumn");
expression.ColumnNames.Add("OtherColumn");
string sql = generator.Generate(expression);
sql.ShouldBe("ALTER TABLE \"NewTable\" DROP \"NewColumn\";" + Environment.NewLine +
"ALTER TABLE \"NewTable\" DROP \"OtherColumn\"");
}
示例15: Generate
public override string Generate(DeleteColumnExpression expression)
{
return String.Format(DropColumn, Quoter.QuoteTableName(expression.TableName), Quoter.QuoteColumnName(expression.ColumnName));
}