本文整理汇总了C#中FluentMigrator.Expressions.DeleteColumnExpression类的典型用法代码示例。如果您正苦于以下问题:C# DeleteColumnExpression类的具体用法?C# DeleteColumnExpression怎么用?C# DeleteColumnExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DeleteColumnExpression类属于FluentMigrator.Expressions命名空间,在下文中一共展示了DeleteColumnExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
开发者ID:xalzan,项目名称:fluentmigrator,代码行数:27,代码来源:SqlServer2000Generator.cs
示例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)));
}
开发者ID:BarsBarsovich,项目名称:fluentmigrator,代码行数:11,代码来源:SqlServerCeGenerator.cs
示例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();
}
开发者ID:VSoftTechnologies,项目名称:fluentmigrator,代码行数:12,代码来源:PostgresGenerator.cs
示例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);
}
开发者ID:Djohnnie,项目名称:Sonarr,代码行数:22,代码来源:NzbDroneSqliteProcessor.cs
示例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));
}
开发者ID:Ang3lFir3,项目名称:fluentmigrator,代码行数:6,代码来源:SqliteGeneratorTests.cs
示例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();
}
开发者ID:kramerpr,项目名称:fluentmigrator,代码行数:13,代码来源:SqlServer2000Generator.cs
示例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)));
}
开发者ID:kramerpr,项目名称:fluentmigrator,代码行数:14,代码来源:SqlServer2000Generator.cs
示例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));
}
开发者ID:timscott,项目名称:fluentmigrator,代码行数:4,代码来源:PostgresGenerator.cs
示例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));
}
开发者ID:ericklaus,项目名称:fluentmigrator,代码行数:6,代码来源:SqlServerCeGenerator.cs
示例10: ErrorIsReturnedWhenTableNameIsNull
public void ErrorIsReturnedWhenTableNameIsNull()
{
var expression = new DeleteColumnExpression { TableName = null };
var errors = ValidationHelper.CollectErrors(expression);
errors.ShouldContain(ErrorMessages.TableNameCannotBeNullOrEmpty);
}
开发者ID:stevehodgkiss,项目名称:fluentmigrator,代码行数:6,代码来源:DeleteColumnExpressionTests.cs
示例11: Generate
public override string Generate(DeleteColumnExpression expression)
{
truncator.Truncate(expression);
return base.Generate(expression);
}
开发者ID:akema-fr,项目名称:fluentmigrator,代码行数:5,代码来源:FirebirdGenerator.cs
示例12: Column
public IDeleteColumnFromTableSyntax Column(string columnName)
{
var expression = new DeleteColumnExpression { ColumnName = columnName };
_context.Expressions.Add(expression);
return new DeleteColumnExpressionBuilder(expression);
}
开发者ID:elfrostie,项目名称:fluentmigrator,代码行数:6,代码来源:DeleteExpressionRoot.cs
示例13: ErrorIsNotReturnedWhenTableNameIsNotNullEmptyString
public void ErrorIsNotReturnedWhenTableNameIsNotNullEmptyString()
{
var expression = new DeleteColumnExpression { TableName = "Bacon" };
var errors = ValidationHelper.CollectErrors(expression);
errors.ShouldNotContain(ErrorMessages.TableNameCannotBeNullOrEmpty);
}
开发者ID:stevehodgkiss,项目名称:fluentmigrator,代码行数:6,代码来源:DeleteColumnExpressionTests.cs
示例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\"");
}
开发者ID:kevin3274,项目名称:fluentmigrator,代码行数:11,代码来源:FirebirdGeneratorTests.cs
示例15: Generate
public override string Generate(DeleteColumnExpression expression)
{
return String.Format(DropColumn, Quoter.QuoteTableName(expression.TableName), Quoter.QuoteColumnName(expression.ColumnName));
}
开发者ID:timscott,项目名称:fluentmigrator,代码行数:4,代码来源:GenericGenerator.cs
示例16: CanDropColumn
public void CanDropColumn()
{
var tableName = "NewTable";
var columnName = "NewColumn";
var expression = new DeleteColumnExpression();
expression.TableName = tableName;
expression.ColumnName = columnName;
var sql = generator.Generate(expression);
var expectedSql =
@"
DECLARE @default sysname, @sql nvarchar(max);
-- get name of default constraint
SELECT @default = name
FROM sys.default_constraints
WHERE parent_object_id = object_id('NewTable')
AND type = 'D'
AND parent_column_id = (
SELECT column_id
FROM sys.columns
WHERE object_id = object_id('NewTable')
AND name = 'NewColumn'
);
-- create alter table command as string and run it
SET @sql = N'ALTER TABLE [NewTable] DROP CONSTRAINT ' + @default;
EXEC sp_executesql @sql;
-- now we can finally drop column
ALTER TABLE [NewTable] DROP COLUMN [NewColumn];";
sql.ShouldBe(expectedSql);
}
开发者ID:Ang3lFir3,项目名称:fluentmigrator,代码行数:36,代码来源:SqlServer2000GeneratorTests.cs
示例17: 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 \"public\".\"NewTable\" DROP COLUMN \"NewColumn\";\r\n" +
"ALTER TABLE \"public\".\"NewTable\" DROP COLUMN \"OtherColumn\"");
}
开发者ID:ibebbs,项目名称:fluentmigrator,代码行数:11,代码来源:PostgresGeneratorTests.cs
示例18: Generate
public override string Generate(DeleteColumnExpression expression)
{
return compatabilityMode.HandleCompatabilty("Sqlite does not support deleting of columns");
}
开发者ID:robinvarg,项目名称:fluentmigrator,代码行数:4,代码来源:SqliteGenerator.cs
示例19: ErrorIsReturnedWhenColumnIsSpecifiedMultipleTimes
public void ErrorIsReturnedWhenColumnIsSpecifiedMultipleTimes()
{
var expression = new DeleteColumnExpression { ColumnNames = { "Bacon", "Bacon" } };
var errors = ValidationHelper.CollectErrors(expression);
errors.ShouldContain(ErrorMessages.ColumnNamesMustBeUnique);
}
开发者ID:BarsBarsovich,项目名称:fluentmigrator,代码行数:6,代码来源:DeleteColumnExpressionTests.cs
示例20: 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();
builder.AppendLine(Generate(new DeleteDefaultConstraintExpression
{
ColumnName = expression.ColumnName,
SchemaName = expression.SchemaName,
TableName = expression.TableName
}));
builder.AppendLine();
builder.Append(String.Format("-- now we can finally drop column\r\nALTER TABLE {0} DROP COLUMN {1};",
Quoter.QuoteTableName(expression.TableName),
Quoter.QuoteColumnName(expression.ColumnName)));
return builder.ToString();
}
开发者ID:Andorbal,项目名称:fluentmigrator,代码行数:20,代码来源:SqlServer2000Generator.cs
注:本文中的FluentMigrator.Expressions.DeleteColumnExpression类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论