本文整理汇总了C#中System.Data.Entity.Migrations.Model.CreateTableOperation类的典型用法代码示例。如果您正苦于以下问题:C# CreateTableOperation类的具体用法?C# CreateTableOperation怎么用?C# CreateTableOperation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CreateTableOperation类属于System.Data.Entity.Migrations.Model命名空间,在下文中一共展示了CreateTableOperation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ForeignKey_should_create_and_add_fk_model
public void ForeignKey_should_create_and_add_fk_model()
{
var createTableOperation = new CreateTableOperation("T");
createTableOperation.Columns.Add(
new ColumnModel(PrimitiveTypeKind.Guid)
{
Name = "Foo"
});
createTableOperation.Columns.Add(
new ColumnModel(PrimitiveTypeKind.Guid)
{
Name = "Bar"
});
var migration = new TestMigration();
var tableBuilder = new TableBuilder<Columns>(createTableOperation, migration);
tableBuilder.ForeignKey(
"P", c => new
{
c.Foo,
c.Bar
}, true, "my_fk");
Assert.Equal(1, migration.Operations.Count());
var addForeignKeyOperation = migration.Operations.Cast<AddForeignKeyOperation>().Single();
Assert.Equal("P", addForeignKeyOperation.PrincipalTable);
Assert.Equal("Foo", addForeignKeyOperation.DependentColumns.First());
Assert.Equal("Bar", addForeignKeyOperation.DependentColumns.Last());
Assert.True(addForeignKeyOperation.CascadeDelete);
Assert.Equal("my_fk", addForeignKeyOperation.Name);
}
示例2: DropTableOperation
public DropTableOperation(string name, CreateTableOperation inverse, object anonymousArguments = null)
: this(name, anonymousArguments)
{
//Contract.Requires(inverse != null);
_inverse = inverse;
}
示例3: Generate
protected override void Generate(CreateTableOperation createTableOperation)
{
string schema, objectName;
this.GetNameParts(createTableOperation.Name, out schema, out objectName);
using (var writer = Writer())
{
writer.WriteLine("IF NOT EXISTS(SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}')\r\nBEGIN", schema, objectName);
writer.Indent++;
writer.Write("CREATE TABLE ");
writer.Write(this.Name(createTableOperation.Name));
writer.Write(" ( ");
int i = 0;
foreach (var column in createTableOperation.Columns)
{
this.AddColumnDefinition(column, writer);
writer.WriteLine("{0}", i != createTableOperation.Columns.Count - 1 ? "," : string.Empty);
i++;
}
writer.Write(" ) ");
writer.Indent--;
writer.Write("\r\nEND");
this.Statement(writer);
}
}
示例4: PrimaryKey_should_set_key_columns_and_name
public void PrimaryKey_should_set_key_columns_and_name()
{
var createTableOperation = new CreateTableOperation("T");
createTableOperation.Columns.Add(
new ColumnModel(PrimitiveTypeKind.Guid)
{
Name = "Foo"
});
createTableOperation.Columns.Add(
new ColumnModel(PrimitiveTypeKind.Guid)
{
Name = "Bar"
});
createTableOperation.Columns.Add(
new ColumnModel(PrimitiveTypeKind.Guid)
{
Name = "Baz"
});
var tableBuilder = new TableBuilder<Columns>(createTableOperation, new TestMigration());
tableBuilder.PrimaryKey(
c => new
{
c.Bar,
c.Foo
}, name: "PK_Custom");
Assert.Equal(2, createTableOperation.PrimaryKey.Columns.Count());
Assert.Equal("Bar", createTableOperation.PrimaryKey.Columns.First());
Assert.Equal("Foo", createTableOperation.PrimaryKey.Columns.Last());
Assert.Equal("PK_Custom", createTableOperation.PrimaryKey.Name);
}
示例5: DropTableOperation
public DropTableOperation(string name, CreateTableOperation inverse, object anonymousArguments = null)
: this(name, anonymousArguments)
{
Check.NotNull(inverse, "inverse");
_inverse = inverse;
}
示例6: Generate
/// <summary>
/// Generates SQL for a <see cref = "CreateTableOperation" />.
/// Generated SQL should be added using the Statement method.
/// </summary>
/// <param name = "createTableOperation">The operation to produce SQL for.</param>
protected virtual void Generate(CreateTableOperation createTableOperation)
{
Contract.Requires(createTableOperation != null);
var parts = createTableOperation.Name.Split(new[] { '.' }, 2);
if (parts.Length > 1)
{
var schema = parts[0];
if (!schema.EqualsIgnoreCase("dbo")
&& !_generatedSchemas.Contains(schema))
{
GenerateCreateSchema(schema);
_generatedSchemas.Add(schema);
}
}
using (var writer = Writer())
{
writer.WriteLine("CREATE TABLE " + Name(createTableOperation.Name) + " (");
writer.Indent++;
var columnCount = createTableOperation.Columns.Count();
createTableOperation.Columns.Each(
(c, i) =>
{
Generate(c, writer);
if (i < columnCount - 1)
{
writer.WriteLine(",");
}
});
if (createTableOperation.PrimaryKey != null)
{
writer.WriteLine(",");
writer.Write("CONSTRAINT ");
writer.Write(Quote(createTableOperation.PrimaryKey.Name));
writer.Write(" PRIMARY KEY (");
writer.Write(createTableOperation.PrimaryKey.Columns.Join(Quote));
writer.WriteLine(")");
}
else
{
writer.WriteLine();
}
writer.Indent--;
writer.Write(")");
Statement(writer);
}
GenerateMakeSystemTable(createTableOperation);
}
示例7: Generate
protected override void Generate(CreateTableOperation cto)
{
if (cto.PrimaryKey != null)
{
cto.PrimaryKey.Name = GetPrimaryKeyName(cto.PrimaryKey.Table);
}
base.Generate(cto);
}
示例8: Generate
protected override void Generate(CreateTableOperation createTableOperation)
{
foreach (var columnModel in createTableOperation.Columns) {
SetDefaultValue(columnModel);
}
base.Generate(createTableOperation);
}
示例9: Can_set_and_get_primary_key
public void Can_set_and_get_primary_key()
{
var addPrimaryKeyOperation = new AddPrimaryKeyOperation();
var table = new CreateTableOperation("T") { PrimaryKey = addPrimaryKeyOperation };
Assert.Same(addPrimaryKeyOperation, table.PrimaryKey);
Assert.Equal("T", addPrimaryKeyOperation.Table);
}
示例10: Generate
protected override void Generate(CreateTableOperation createTableOperation, IndentedTextWriter writer)
{
var isReadonly = ReadonlyEntities.Contains(createTableOperation.Name);
if (!isReadonly)
{
base.Generate(createTableOperation, writer);
}
}
示例11: Inverse_should_produce_drop_table_operation
public void Inverse_should_produce_drop_table_operation()
{
var createTableOperation = new CreateTableOperation("Foo");
var dropTableOperation = (DropTableOperation)createTableOperation.Inverse;
Assert.Equal("Foo", dropTableOperation.Name);
}
示例12: Inverse_should_produce_create_table_operation
public void Inverse_should_produce_create_table_operation()
{
var inverse = new CreateTableOperation("T");
var dropTableOperation = new DropTableOperation("T", inverse);
Assert.Equal("T", dropTableOperation.Name);
Assert.Same(inverse, dropTableOperation.Inverse);
}
示例13: Annotations_should_return_set_annotations
public void Annotations_should_return_set_annotations()
{
Assert.Empty(new CreateTableOperation("Foo").Annotations);
Assert.Empty(new CreateTableOperation("Foo", null).Annotations);
var operation = new CreateTableOperation("Foo", new Dictionary<string, object> { { "A1", "V1" } });
Assert.Equal("V1", operation.Annotations["A1"]);
}
示例14: Generate
protected override void Generate(CreateTableOperation createTableOperation)
{
if ((createTableOperation.PrimaryKey != null)
&& !createTableOperation.PrimaryKey.IsClustered)
{
createTableOperation.PrimaryKey.IsClustered = true;
}
base.Generate(createTableOperation);
}
示例15: Can_get_and_set_create_table_operation
public void Can_get_and_set_create_table_operation()
{
var createTableOperation = new CreateTableOperation("T");
var dropPrimaryKeyOperation = new DropPrimaryKeyOperation
{
CreateTableOperation = createTableOperation
};
Assert.Same(createTableOperation, dropPrimaryKeyOperation.CreateTableOperation);
}