本文整理汇总了C#中EntityType.SetTableName方法的典型用法代码示例。如果您正苦于以下问题:C# EntityType.SetTableName方法的具体用法?C# EntityType.SetTableName怎么用?C# EntityType.SetTableName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityType
的用法示例。
在下文中一共展示了EntityType.SetTableName方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateModel
private static IModel CreateModel()
{
var model = new Metadata.Model { StorageName = "MyDatabase" };
var dependentEntityType = new EntityType("Dependent");
dependentEntityType.SetSchema("dbo");
dependentEntityType.SetTableName("MyTable0");
var principalEntityType = new EntityType("Principal");
principalEntityType.SetSchema("dbo");
principalEntityType.SetTableName("MyTable1");
var dependentProperty = dependentEntityType.AddProperty("Id", typeof(int));
var principalProperty = principalEntityType.AddProperty("Id", typeof(int));
principalProperty.ValueGenerationOnSave = ValueGenerationOnSave.WhenInserting;
model.AddEntityType(principalEntityType);
model.AddEntityType(dependentEntityType);
principalProperty.Annotations.Add(new Annotation(
MetadataExtensions.Annotations.StorageTypeName, "int"));
dependentProperty.Annotations.Add(new Annotation(
MetadataExtensions.Annotations.StorageTypeName, "int"));
dependentEntityType.SetKey(dependentProperty);
principalEntityType.SetKey(principalProperty);
dependentEntityType.GetKey().SetKeyName("MyPK0");
principalEntityType.GetKey().SetKeyName("MyPK1");
var foreignKey = dependentEntityType.AddForeignKey(principalEntityType.GetKey(), dependentProperty);
foreignKey.SetKeyName("MyFK");
foreignKey.Annotations.Add(new Annotation(
MetadataExtensions.Annotations.CascadeDelete, "True"));
var index = dependentEntityType.AddIndex(dependentProperty);
index.SetIndexName("MyIndex");
index.IsUnique = true;
return model;
}
示例2: Diff_finds_dropped_table
public void Diff_finds_dropped_table()
{
var sourceModel = CreateModel();
var targetModel = CreateModel();
var principalEntityType = targetModel.GetEntityType("Principal");
var dependentEntityType = new EntityType("OldDependent");
dependentEntityType.SetTableName("MyOldTable");
dependentEntityType.SetSchema("dbo");
var dependentProperty = dependentEntityType.AddProperty("Id", typeof(int));
sourceModel.AddEntityType(dependentEntityType);
dependentProperty.Annotations.Add(new Annotation(
MetadataExtensions.Annotations.StorageTypeName, "int"));
dependentEntityType.SetKey(dependentProperty);
dependentEntityType.GetKey().SetKeyName("MyOldPK");
var foreignKey = dependentEntityType.AddForeignKey(principalEntityType.GetKey(), dependentProperty);
foreignKey.SetKeyName("MyOldFK");
foreignKey.Annotations.Add(new Annotation(
MetadataExtensions.Annotations.CascadeDelete, "True"));
var operations = new ModelDiffer(new DatabaseBuilder()).Diff(sourceModel, targetModel);
Assert.Equal(1, operations.Count);
Assert.IsType<DropTableOperation>(operations[0]);
var dropTableOperation = (DropTableOperation)operations[0];
Assert.Equal("dbo.MyOldTable", dropTableOperation.TableName);
}
示例3: Diff_finds_created_table
public void Diff_finds_created_table()
{
var sourceModel = CreateModel();
var targetModel = CreateModel();
var principalEntityType = targetModel.GetEntityType("Principal");
var dependentEntityType = new EntityType("NewDependent");
dependentEntityType.SetTableName("MyNewTable");
dependentEntityType.SetSchema("dbo");
var dependentProperty = dependentEntityType.AddProperty("Id", typeof(int));
targetModel.AddEntityType(dependentEntityType);
dependentProperty.Annotations.Add(new Annotation(
MetadataExtensions.Annotations.StorageTypeName, "int"));
dependentEntityType.SetKey(dependentProperty);
dependentEntityType.GetKey().SetKeyName("MyNewPK");
var foreignKey = dependentEntityType.AddForeignKey(principalEntityType.GetKey(), dependentProperty);
foreignKey.SetKeyName("MyNewFK");
foreignKey.Annotations.Add(new Annotation(
MetadataExtensions.Annotations.CascadeDelete, "True"));
var operations = new ModelDiffer(new DatabaseBuilder()).Diff(sourceModel, targetModel);
Assert.Equal(2, operations.Count);
Assert.IsType<CreateTableOperation>(operations[0]);
Assert.IsType<AddForeignKeyOperation>(operations[1]);
var createTableOperation = (CreateTableOperation)operations[0];
Assert.Equal("dbo.MyNewTable", createTableOperation.Table.Name);
Assert.Equal(1, createTableOperation.Table.Columns.Count);
Assert.Equal("Id", createTableOperation.Table.Columns[0].Name);
Assert.Equal(typeof(int), createTableOperation.Table.Columns[0].ClrType);
Assert.NotNull(createTableOperation.Table.PrimaryKey);
Assert.Equal("MyNewPK", createTableOperation.Table.PrimaryKey.Name);
Assert.Equal(1, createTableOperation.Table.ForeignKeys.Count);
Assert.Equal("MyNewFK", createTableOperation.Table.ForeignKeys[0].Name);
Assert.True(createTableOperation.Table.ForeignKeys[0].CascadeDelete);
var addForeignKeyOperation = (AddForeignKeyOperation)operations[1];
Assert.Equal("MyNewFK", addForeignKeyOperation.ForeignKeyName);
Assert.Equal("dbo.MyNewTable", addForeignKeyOperation.TableName);
Assert.Equal("dbo.MyTable1", addForeignKeyOperation.ReferencedTableName);
Assert.Equal(new[] { "Id" }, addForeignKeyOperation.ColumnNames);
Assert.Equal(new[] { "Id" }, addForeignKeyOperation.ReferencedColumnNames);
Assert.True(addForeignKeyOperation.CascadeDelete);
}
示例4: Entity_table_name_can_be_different_from_name
public void Entity_table_name_can_be_different_from_name()
{
var entityType = new EntityType(typeof(Customer));
entityType.SetTableName("CustomerTable");
Assert.Equal("CustomerTable", entityType.TableName());
}
示例5: CreateProperty
private static Property CreateProperty(Type propertyType, ValueGenerationOnAdd valueGeneration)
{
var entityType = new EntityType("MyType");
var property = entityType.AddProperty("MyProperty", propertyType);
property.ValueGenerationOnAdd = valueGeneration;
entityType.SetTableName("MyTable");
new Model().AddEntityType(entityType);
return property;
}
示例6: CreateModelWithForeignKeys
private static IModel CreateModelWithForeignKeys()
{
var model = new Model();
var houseType = new EntityType("Ho!use[]");
var houseId = houseType.AddProperty("Id", typeof(int));
houseType.SetKey(houseId);
model.AddEntityType(houseType);
var customerType = new EntityType(@"Customer");
var customerId = customerType.AddProperty("Id", typeof(int));
var customerFkProperty = customerType.AddProperty("HouseId", typeof(int));
customerFkProperty.SetColumnName(@"House[""Id]Column");
customerType.SetSchema("dbo");
customerType.SetTableName(@"Cus[""om.er]s");
customerType.SetKey(customerId);
customerType.GetKey().SetKeyName(@"My[""PK]");
customerType.GetKey().Annotations.Add(new Annotation(@"My""PK""Annotat!on", @"""Foo"""));
var customerFk = customerType.AddForeignKey(houseType.GetKey(), customerFkProperty);
customerFk.SetKeyName(@"My_[""FK]");
customerFk.Annotations.Add(new Annotation(@"My""FK""Annotation", @"""Bar"""));
model.AddEntityType(customerType);
var orderType = new EntityType(@"Order");
var orderId = orderType.AddProperty(@"OrderId", typeof(int));
var orderFK = orderType.AddProperty(@"CustomerId", typeof(int));
orderType.SetSchema("dbo");
orderType.SetKey(orderId);
orderType.SetTableName(@"Ord[""e.r]s");
orderType.AddForeignKey(customerType.GetKey(), orderFK);
orderType.Annotations.Add(new Annotation("Random annotation", "42"));
model.AddEntityType(orderType);
return model;
}
示例7: CreateModel
private static IModel CreateModel()
{
var model = new Model();
var entityType = new EntityType("Entity");
var property = entityType.AddProperty("Id", typeof(int));
entityType.SetTableName("MyTable");
entityType.SetSchema("dbo");
entityType.SetKey(property);
entityType.GetKey().SetKeyName("MyPK");
model.AddEntityType(entityType);
return model;
}
示例8: CreateProperty
private static Property CreateProperty()
{
var entityType = new EntityType("MyType");
var property = entityType.AddProperty("MyProperty", typeof(string));
entityType.SetTableName("MyTable");
new Model().AddEntityType(entityType);
return property;
}