本文整理汇总了C#中MigrationBuilder.AddPrimaryKey方法的典型用法代码示例。如果您正苦于以下问题:C# MigrationBuilder.AddPrimaryKey方法的具体用法?C# MigrationBuilder.AddPrimaryKey怎么用?C# MigrationBuilder.AddPrimaryKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MigrationBuilder
的用法示例。
在下文中一共展示了MigrationBuilder.AddPrimaryKey方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Down
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_Translation_Content_ContentId", table: "Translation");
migrationBuilder.DropPrimaryKey(name: "PK_Content", table: "Content");
migrationBuilder.DropColumn(name: "Id", table: "Content");
migrationBuilder.AddColumn<Guid>(
name: "ContentContentGuid",
table: "Translation",
nullable: true);
migrationBuilder.AddColumn<Guid>(
name: "ContentGuid",
table: "Content",
nullable: false,
defaultValueSql: "newsequentialid()");
migrationBuilder.AddPrimaryKey(
name: "PK_Content",
table: "Content",
column: "ContentGuid");
migrationBuilder.AddForeignKey(
name: "FK_Translation_Content_ContentContentGuid",
table: "Translation",
column: "ContentContentGuid",
principalTable: "Content",
principalColumn: "ContentGuid",
onDelete: ReferentialAction.Restrict);
}
开发者ID:nettsundere,项目名称:PersonalWebsite,代码行数:26,代码来源:20151128025750_ReplaceGuidWithIdForContentsAndTranslations.cs
示例2: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(name: "PK_LpaUserClaim", table: "UserClaims");
migrationBuilder.AddPrimaryKey(
name: "PK_LpaUserClaim",
table: "UserClaims",
columns: new[] { "UserId", "ClaimId" })
.Annotation("SqlServer:Clustered", true);
}
示例3: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_MasterToRole_Role_RoleId", table: "MasterToRole");
migrationBuilder.DropPrimaryKey(name: "PK_MasterToRole", table: "MasterToRole");
migrationBuilder.DropColumn(name: "RoleId", table: "MasterToRole");
migrationBuilder.DropTable("Role");
migrationBuilder.AlterColumn<string>(
name: "IdentityRoleId",
table: "MasterToRole",
nullable: false);
migrationBuilder.AddPrimaryKey(
name: "PK_MasterToRole",
table: "MasterToRole",
columns: new[] { "IdentityRoleId", "MasterID" });
}
示例4: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_IdentityRoleClaim<string>_IdentityRole_RoleId", table: "AspNetRoleClaims");
migrationBuilder.DropForeignKey(name: "FK_IdentityUserRole<string>_IdentityRole_RoleId", table: "AspNetUserRoles");
migrationBuilder.DropPrimaryKey(name: "PK_IdentityRole", table: "AspNetRoles");
migrationBuilder.AddPrimaryKey(
name: "PK_ApplicationRole",
table: "AspNetRoles",
column: "Id");
migrationBuilder.AddForeignKey(
name: "FK_IdentityRoleClaim<string>_ApplicationRole_RoleId",
table: "AspNetRoleClaims",
column: "RoleId",
principalTable: "AspNetRoles",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_IdentityUserRole<string>_ApplicationRole_RoleId",
table: "AspNetUserRoles",
column: "RoleId",
principalTable: "AspNetRoles",
principalColumn: "Id");
}
示例5: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_Translation_Content_ContentContentGuid", table: "Translation");
migrationBuilder.DropPrimaryKey(name: "PK_Content", table: "Content");
migrationBuilder.DropColumn(name: "ContentContentGuid", table: "Translation");
migrationBuilder.DropColumn(name: "ContentGuid", table: "Content");
migrationBuilder.AddColumn<int>(
name: "Id",
table: "Content",
nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
migrationBuilder.AddPrimaryKey(
name: "PK_Content",
table: "Content",
column: "Id");
migrationBuilder.AddForeignKey(
name: "FK_Translation_Content_ContentId",
table: "Translation",
column: "ContentId",
principalTable: "Content",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
开发者ID:nettsundere,项目名称:PersonalWebsite,代码行数:23,代码来源:20151128025750_ReplaceGuidWithIdForContentsAndTranslations.cs
示例6: Down
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropPrimaryKey(name: "PK_MasterToRole", table: "MasterToRole");
migrationBuilder.CreateTable(
name: "Role",
columns: table => new
{
Id = table.Column<string>(nullable: false),
ConcurrencyStamp = table.Column<string>(nullable: true),
Name = table.Column<string>(nullable: true),
NormalizedName = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Role", x => x.Id);
});
migrationBuilder.AlterColumn<string>(
name: "IdentityRoleId",
table: "MasterToRole",
nullable: true);
migrationBuilder.AddColumn<string>(
name: "RoleId",
table: "MasterToRole",
nullable: false,
defaultValue: "");
migrationBuilder.AddPrimaryKey(
name: "PK_MasterToRole",
table: "MasterToRole",
columns: new[] { "RoleId", "MasterID" });
migrationBuilder.AddForeignKey(
name: "FK_MasterToRole_Role_RoleId",
table: "MasterToRole",
column: "RoleId",
principalTable: "Role",
principalColumn: "Id");
}
示例7: AddPrimaryKey_adds_operation
public void AddPrimaryKey_adds_operation()
{
var builder = new MigrationBuilder();
builder.AddPrimaryKey("dbo.MyTable", "MyPK", new[] { "Foo", "Bar" }, isClustered: true);
Assert.Equal(1, builder.Operations.Count);
Assert.IsType<AddPrimaryKeyOperation>(builder.Operations[0]);
var operation = (AddPrimaryKeyOperation)builder.Operations[0];
Assert.Equal("dbo.MyTable", operation.TableName);
Assert.Equal("MyPK", operation.PrimaryKeyName);
Assert.Equal(new[] { "Foo", "Bar" }, operation.ColumnNames);
Assert.True(operation.IsClustered);
}