本文整理汇总了C#中System.Data.Entity.Migrations.Model.AddColumnOperation类的典型用法代码示例。如果您正苦于以下问题:C# AddColumnOperation类的具体用法?C# AddColumnOperation怎么用?C# AddColumnOperation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AddColumnOperation类属于System.Data.Entity.Migrations.Model命名空间,在下文中一共展示了AddColumnOperation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
protected override void Generate(AddColumnOperation addColumnOperation)
{
SetCreatedUtcColumn(addColumnOperation.Column);
AddDefaultValue(addColumnOperation.Column);
base.Generate(addColumnOperation);
}
示例2: Generate
protected virtual IEnumerable<MigrationStatement> Generate(AddColumnOperation operation)
{
using (var writer = SqlWriter())
{
writer.Write("ALTER TABLE ");
writer.Write(Quote(operation.Table));
writer.Write(" ADD ");
var column = operation.Column;
writer.Write(Generate(column));
if (column.IsNullable != null
&& !column.IsNullable.Value
&& column.DefaultValue == null
&& string.IsNullOrWhiteSpace(column.DefaultValueSql)
&& !column.IsIdentity
&& !column.IsTimestamp)
{
writer.Write(" DEFAULT ");
if (column.Type == PrimitiveTypeKind.DateTime)
{
writer.Write(WriteValue(DateTime.Parse("1970-01-01 00:00:00", CultureInfo.InvariantCulture)));
}
else
{
writer.Write(WriteValue((dynamic)column.ClrDefaultValue));
}
}
yield return Statement(writer);
}
}
示例3: Generate_should_output_invariant_decimals_when_non_invariant_culture
public void Generate_should_output_invariant_decimals_when_non_invariant_culture()
{
var migrationProvider = new SqlServerMigrationSqlGenerator();
var addColumnOperation
= new AddColumnOperation(
"T",
new ColumnModel(PrimitiveTypeKind.Binary)
{
Name = "C",
DefaultValue = 123.45m
});
var lastCulture = Thread.CurrentThread.CurrentCulture;
try
{
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("nl-NL");
var sql = migrationProvider.Generate(new[] { addColumnOperation }, "2008").Join(s => s.Sql, Environment.NewLine);
Assert.Contains("ALTER TABLE [T] ADD [C] [varbinary](max) DEFAULT 123.45", sql);
}
finally
{
Thread.CurrentThread.CurrentCulture = lastCulture;
}
}
示例4: Inverse_should_produce_drop_column_operation
public void Inverse_should_produce_drop_column_operation()
{
var inverse = new AddColumnOperation("T", new ColumnModel(PrimitiveTypeKind.Binary));
var dropColumnOperation = new DropColumnOperation("T", "c", inverse);
Assert.Same(inverse, dropColumnOperation.Inverse);
}
示例5: Can_get_and_set_table_and_column_info
public void Can_get_and_set_table_and_column_info()
{
var column = new ColumnModel(PrimitiveTypeKind.Decimal);
var addColumnOperation = new AddColumnOperation("T", column);
Assert.Equal("T", addColumnOperation.Table);
Assert.Same(column, addColumnOperation.Column);
}
示例6: Generate
protected virtual MigrationStatement Generate(AddColumnOperation op)
{
if (op == null) return null;
MigrationStatement stmt = new MigrationStatement();
stmt.Sql = string.Format("alter table `{0}` add column `{1}`",
op.Table, op.Column.Name) + " " + Generate(op.Column);
return stmt;
}
示例7: Inverse_should_produce_drop_column_operation
public void Inverse_should_produce_drop_column_operation()
{
var column = new ColumnModel(PrimitiveTypeKind.Decimal) { Name = "C" };
var addColumnOperation = new AddColumnOperation("T", column);
var dropColumnOperation = (DropColumnOperation)addColumnOperation.Inverse;
Assert.Equal("C", dropColumnOperation.Name);
Assert.Equal("T", dropColumnOperation.Table);
}
示例8: DropColumnOperation
public DropColumnOperation(
string table, string name, AddColumnOperation inverse, object anonymousArguments = null)
: base(anonymousArguments)
{
//Contract.Requires(!string.IsNullOrWhiteSpace(table));
//Contract.Requires(!string.IsNullOrWhiteSpace(name));
_table = table;
_name = name;
_inverse = inverse;
}
示例9: DropColumnOperation
public DropColumnOperation(
string table, string name, AddColumnOperation inverse, object anonymousArguments = null)
: base(anonymousArguments)
{
Check.NotEmpty(table, "table");
Check.NotEmpty(name, "name");
_table = table;
_name = name;
_inverse = inverse;
}
示例10: Inverse_should_return_given_AddColumnOperation
public void Inverse_should_return_given_AddColumnOperation()
{
var inverse = new AddColumnOperation("T", new ColumnModel(PrimitiveTypeKind.Binary));
var dropColumnOperation = new DropColumnOperation("T", "c", inverse);
Assert.Same(inverse, dropColumnOperation.Inverse);
dropColumnOperation = new DropColumnOperation("T", "c", null, inverse);
Assert.Same(inverse, dropColumnOperation.Inverse);
}
示例11: GenerateCanOutputAddColumnStatementWhenNonNullableAndNoDefaultProvided
public void GenerateCanOutputAddColumnStatementWhenNonNullableAndNoDefaultProvided()
{
var migrationSqlGenerator = new PostgreSqlMigrationSqlGenerator();
var column = new ColumnModel(PrimitiveTypeKind.Int32)
{
Name = "Bar",
IsNullable = false
};
var addColumnOperation = new AddColumnOperation("Foo", column);
var sql = migrationSqlGenerator.Generate(new[] { addColumnOperation }, "9.2").Join(s => s.Sql, Environment.NewLine);
Assert.True(sql.Contains("ALTER TABLE \"Foo\" ADD \"Bar\" integer NOT NULL DEFAULT 0"));
}
开发者ID:darionato,项目名称:PostgreSqlMigrationSqlGenerator,代码行数:15,代码来源:PostgreSqlMigrationSqlGeneretorTest.cs
示例12: GenerateCanOutputAddColumnStatement
public void GenerateCanOutputAddColumnStatement(PrimitiveTypeKind type, string typeName)
{
var migrationSqlGenerator = new PostgreSqlMigrationSqlGenerator();
var column = new ColumnModel(type)
{
Name = "Bar",
IsIdentity = true
};
var addColumnOperation = new AddColumnOperation("Foo", column);
var sql = migrationSqlGenerator.Generate(
new[] { addColumnOperation }, "9.2").Join(s => s.Sql, Environment.NewLine);
Assert.True(sql.Contains(string.Format("ALTER TABLE \"Foo\" ADD \"Bar\" {0}", typeName)));
}
开发者ID:darionato,项目名称:PostgreSqlMigrationSqlGenerator,代码行数:16,代码来源:PostgreSqlMigrationSqlGeneretorTest.cs
示例13: Inverse_should_produce_drop_column_operation
public void Inverse_should_produce_drop_column_operation()
{
var column = new ColumnModel(PrimitiveTypeKind.Decimal)
{
Name = "C",
Annotations = new Dictionary<string, AnnotationValues> { { "A1", new AnnotationValues(null, "V1") } }
};
var addColumnOperation
= new AddColumnOperation("T", column);
var dropColumnOperation = (DropColumnOperation)addColumnOperation.Inverse;
Assert.Equal("C", dropColumnOperation.Name);
Assert.Equal("T", dropColumnOperation.Table);
Assert.Equal("V1", dropColumnOperation.RemovedAnnotations["A1"]);
}
示例14: Generate_can_output_add_timestamp_store_type_column_operation
public void Generate_can_output_add_timestamp_store_type_column_operation()
{
var migrationProvider = new SqlServerMigrationSqlGenerator();
var addColumnOperation
= new AddColumnOperation(
"T",
new ColumnModel(PrimitiveTypeKind.Binary)
{
IsNullable = false,
Name = "C",
StoreType = "timestamp"
});
var sql = migrationProvider.Generate(new[] { addColumnOperation }, "2008").Join(s => s.Sql, Environment.NewLine);
Assert.True(sql.Contains("ALTER TABLE [T] ADD [C] [timestamp] NOT NULL"));
}
示例15: Generate_can_output_add_rowversion_store_type_column_operation
public void Generate_can_output_add_rowversion_store_type_column_operation()
{
var migrationSqlGenerator = new SqlServerMigrationSqlGenerator();
var addColumnOperation
= new AddColumnOperation(
"T",
new ColumnModel(PrimitiveTypeKind.Binary)
{
IsNullable = false,
Name = "C",
StoreType = "RowVersion"
});
var sql = migrationSqlGenerator.Generate(new[] { addColumnOperation }, "2008").Join(s => s.Sql, Environment.NewLine);
Assert.Contains("ALTER TABLE [T] ADD [C] [RowVersion] NOT NULL", sql);
}