本文整理汇总了C#中MigrationBuilder.RenameTable方法的典型用法代码示例。如果您正苦于以下问题:C# MigrationBuilder.RenameTable方法的具体用法?C# MigrationBuilder.RenameTable怎么用?C# MigrationBuilder.RenameTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MigrationBuilder
的用法示例。
在下文中一共展示了MigrationBuilder.RenameTable方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameTable(
name: "PropertyChange",
newName: "property_changes");
migrationBuilder.RenameTable(
name: "ModelChange",
newName: "model_changes");
}
示例2: Up
public override void Up(MigrationBuilder migration)
{
migration.DropForeignKey(name: "FK_Registration_Member_MemberId", table: "Registration");
migration.DropColumn(name: "MemberId", table: "Registration");
migration.DropTable("Member");
migration.AddColumn(
name: "UserId",
table: "Registration",
type: "nvarchar(450)",
nullable: true);
migration.RenameTable(
name: "AspNetUsers",
newName: "Users");
migration.AddColumn(
name: "Name",
table: "Users",
type: "nvarchar(100)",
nullable: true);
migration.AddForeignKey(
name: "FK_Registration_ApplicationUser_UserId",
table: "Registration",
column: "UserId",
referencedTable: "Users",
referencedColumn: "Id");
}
示例3: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_CourseAssignment_Instructor_InstructorID",
table: "CourseAssignment");
migrationBuilder.DropForeignKey(
name: "FK_Department_Instructor_InstructorID",
table: "Department");
migrationBuilder.DropForeignKey(
name: "FK_Enrollment_Student_StudentID",
table: "Enrollment");
migrationBuilder.DropIndex(name: "IX_Enrollment_StudentID", table: "Enrollment");
migrationBuilder.RenameTable(name: "Instructor", newName: "Person");
migrationBuilder.AddColumn<DateTime>(name: "EnrollmentDate", table: "Person", nullable: true);
migrationBuilder.AddColumn<string>(name: "Discriminator", table: "Person", nullable: false, maxLength: 128, defaultValue: "Instructor");
migrationBuilder.AlterColumn<DateTime>(name: "HireDate", table: "Person", nullable: true);
migrationBuilder.AddColumn<int>(name: "OldId", table: "Person", nullable: true);
// Copy existing Student data into new Person table.
migrationBuilder.Sql("INSERT INTO dbo.Person (LastName, FirstName, HireDate, EnrollmentDate, Discriminator, OldId) SELECT LastName, FirstName, null AS HireDate, EnrollmentDate, 'Student' AS Discriminator, ID AS OldId FROM dbo.Student");
// Fix up existing relationships to match new PK's.
migrationBuilder.Sql("UPDATE dbo.Enrollment SET StudentId = (SELECT ID FROM dbo.Person WHERE OldId = Enrollment.StudentId AND Discriminator = 'Student')");
// Remove temporary key
migrationBuilder.DropColumn(name: "OldID", table: "Person");
migrationBuilder.DropTable(
name: "Student");
migrationBuilder.AddForeignKey(
name: "FK_Enrollment_Person_StudentID",
table: "Enrollment",
column: "StudentID",
principalTable: "Person",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
migrationBuilder.CreateIndex(
name: "IX_Enrollment_StudentID",
table: "Enrollment",
column: "StudentID");
}
示例4: Down
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_IdentityRoleClaim<string>_IdentityRole_RoleId", table: "AspNetRoleClaims");
migrationBuilder.DropForeignKey(name: "FK_IdentityUserClaim<string>_ApplicationUser_UserId", table: "AspNetUserClaims");
migrationBuilder.DropForeignKey(name: "FK_IdentityUserLogin<string>_ApplicationUser_UserId", table: "AspNetUserLogins");
migrationBuilder.DropForeignKey(name: "FK_IdentityUserRole<string>_IdentityRole_RoleId", table: "AspNetUserRoles");
migrationBuilder.DropForeignKey(name: "FK_IdentityUserRole<string>_ApplicationUser_UserId", table: "AspNetUserRoles");
migrationBuilder.AddForeignKey(
name: "FK_IdentityRoleClaim<string>_IdentityRole_RoleId",
table: "AspNetRoleClaims",
column: "RoleId",
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_IdentityUserClaim<string>_ApplicationUser_UserId",
table: "AspNetUserClaims",
column: "UserId",
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_IdentityUserLogin<string>_ApplicationUser_UserId",
table: "AspNetUserLogins",
column: "UserId",
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_IdentityUserRole<string>_IdentityRole_RoleId",
table: "AspNetUserRoles",
column: "RoleId",
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_IdentityUserRole<string>_ApplicationUser_UserId",
table: "AspNetUserRoles",
column: "UserId",
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.RenameTable(
name: "Votos",
newName: "Voto");
}
示例5: Down
public override void Down(MigrationBuilder migration)
{
migration.DropForeignKey(name: "FK_Registration_ApplicationUser_UserId", table: "Registration");
migration.DropColumn(name: "UserId", table: "Registration");
migration.DropColumn(name: "Name", table: "Users");
migration.CreateTable(
name: "Member",
columns: table => new
{
Id = table.Column(type: "int", nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", "IdentityColumn"),
Email = table.Column(type: "nvarchar(max)", nullable: true),
Name = table.Column(type: "nvarchar(100)", nullable: true),
UserId = table.Column(type: "nvarchar(450)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Member", x => x.Id);
table.ForeignKey(
name: "FK_Member_ApplicationUser_UserId",
columns: x => x.UserId,
referencedTable: "AspNetUsers",
referencedColumn: "Id");
});
migration.AddColumn(
name: "MemberId",
table: "Registration",
type: "int",
nullable: true);
migration.AddForeignKey(
name: "FK_Registration_Member_MemberId",
table: "Registration",
column: "MemberId",
referencedTable: "Member",
referencedColumn: "Id");
migration.RenameTable(
name: "Users",
newName: "AspNetUsers");
}
示例6: RenameTable_adds_operation
public void RenameTable_adds_operation()
{
var builder = new MigrationBuilder();
builder.RenameTable("dbo.MyTable", "MyTable2");
Assert.Equal(1, builder.Operations.Count);
Assert.IsType<RenameTableOperation>(builder.Operations[0]);
var operation = (RenameTableOperation)builder.Operations[0];
Assert.Equal("dbo.MyTable", operation.TableName);
Assert.Equal("MyTable2", operation.NewTableName);
}
示例7: Down
protected override void Down(MigrationBuilder migrationBuilder)
=> migrationBuilder.RenameTable(
name: "Table2",
newName: "Table1");
示例8: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameTable(
name: "Table1",
newName: "Table2");
}