本文整理汇总了C#中MigrationBuilder.AddForeignKey方法的典型用法代码示例。如果您正苦于以下问题:C# MigrationBuilder.AddForeignKey方法的具体用法?C# MigrationBuilder.AddForeignKey怎么用?C# MigrationBuilder.AddForeignKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MigrationBuilder
的用法示例。
在下文中一共展示了MigrationBuilder.AddForeignKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Down
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_SkillToTag_Skill_SkillId", schema: "skill", table: "SkillToTag");
migrationBuilder.DropForeignKey(name: "FK_SkillToTag_SkillTag_TagId", schema: "skill", table: "SkillToTag");
migrationBuilder.DropTable(name: "Comment", schema: "blog");
migrationBuilder.DropTable(name: "Entry", schema: "blog");
migrationBuilder.AddForeignKey(
name: "FK_SkillToTag_Skill_SkillId",
schema: "skill",
table: "SkillToTag",
column: "SkillId",
principalSchema: "skill",
principalTable: "Skill",
principalColumn: "SkillId",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_SkillToTag_SkillTag_TagId",
schema: "skill",
table: "SkillToTag",
column: "TagId",
principalSchema: "skill",
principalTable: "Tag",
principalColumn: "TagId",
onDelete: ReferentialAction.Restrict);
}
示例2: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_Student_Teacher_TeacherID", table: "Student");
migrationBuilder.CreateTable(
name: "School",
columns: table => new
{
ID = table.Column<long>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
Name = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_School", x => x.ID);
});
migrationBuilder.AddColumn<long>(
name: "SchoolID",
table: "Teacher",
nullable: false,
defaultValue: 0L);
migrationBuilder.AddForeignKey(
name: "FK_Student_Teacher_TeacherID",
table: "Student",
column: "TeacherID",
principalTable: "Teacher",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Teacher_School_SchoolID",
table: "Teacher",
column: "SchoolID",
principalTable: "School",
principalColumn: "ID",
onDelete: ReferentialAction.Cascade);
}
开发者ID:MaxxDelusional,项目名称:EntityFrameworkContainsExample,代码行数:35,代码来源:20160125185654_AddedSchools.cs
示例3: Down
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_Photo_Album_AlbumId", table: "Photo");
migrationBuilder.DropForeignKey(name: "FK_UserRole_Role_RoleId", table: "UserRole");
migrationBuilder.DropForeignKey(name: "FK_UserRole_User_UserId", table: "UserRole");
migrationBuilder.AddColumn<string>(
name: "Throwaway",
table: "Album",
nullable: true);
migrationBuilder.AddForeignKey(
name: "FK_Photo_Album_AlbumId",
table: "Photo",
column: "AlbumId",
principalTable: "Album",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_UserRole_Role_RoleId",
table: "UserRole",
column: "RoleId",
principalTable: "Role",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_UserRole_User_UserId",
table: "UserRole",
column: "UserId",
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
示例4: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateIndex(
name: "IX_UserQuestionData_QuestionId",
table: "UserQuestionData",
column: "QuestionId");
migrationBuilder.CreateIndex(
name: "IX_UserQuestionData_UserId",
table: "UserQuestionData",
column: "UserId");
migrationBuilder.AddForeignKey(
name: "FK_UserQuestionData_Questions_QuestionId",
table: "UserQuestionData",
column: "QuestionId",
principalTable: "Questions",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_UserQuestionData_Users_UserId",
table: "UserQuestionData",
column: "UserId",
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
示例5: Down
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_PriceHistory_Stock_StockId", table: "PriceHistory");
migrationBuilder.DropForeignKey(name: "FK_Txn_Stock_StockId", table: "Txn");
migrationBuilder.AlterColumn<decimal>(
name: "Open",
table: "PriceHistory",
nullable: false);
migrationBuilder.AlterColumn<decimal>(
name: "Low",
table: "PriceHistory",
nullable: false);
migrationBuilder.AlterColumn<decimal>(
name: "High",
table: "PriceHistory",
nullable: false);
migrationBuilder.AlterColumn<decimal>(
name: "Close",
table: "PriceHistory",
nullable: false);
migrationBuilder.AddForeignKey(
name: "FK_PriceHistory_Stock_StockId",
table: "PriceHistory",
column: "StockId",
principalTable: "Stock",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_Txn_Stock_StockId",
table: "Txn",
column: "StockId",
principalTable: "Stock",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
示例6: Down
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_Produto_Categoria_CategoriaID", table: "Produto");
migrationBuilder.DropForeignKey(name: "FK_ProdutoVenda_Produto_ProdutoID", table: "ProdutoVenda");
migrationBuilder.DropForeignKey(name: "FK_ProdutoVenda_Venda_VendaID", table: "ProdutoVenda");
migrationBuilder.DropColumn(name: "Discriminator", table: "Usuario");
migrationBuilder.DropColumn(name: "CPF", table: "Usuario");
migrationBuilder.DropColumn(name: "CNPJ", table: "Usuario");
migrationBuilder.AddForeignKey(
name: "FK_Produto_Categoria_CategoriaID",
table: "Produto",
column: "CategoriaID",
principalTable: "Categoria",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_ProdutoVenda_Produto_ProdutoID",
table: "ProdutoVenda",
column: "ProdutoID",
principalTable: "Produto",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_ProdutoVenda_Venda_VendaID",
table: "ProdutoVenda",
column: "VendaID",
principalTable: "Venda",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
}
示例7: Down
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_ReleaseBatchItem_ReleaseBatch_ReleaseBatchId", schema: "kraken", table: "ReleaseBatchItem");
migrationBuilder.DropForeignKey(name: "FK_ReleaseBatchLogo_ReleaseBatch_ReleaseBatchId", schema: "kraken", table: "ReleaseBatchLogo");
migrationBuilder.DropColumn(name: "IsLocked", schema: "kraken", table: "ReleaseBatch");
migrationBuilder.DropColumn(name: "LockComment", schema: "kraken", table: "ReleaseBatch");
migrationBuilder.DropColumn(name: "LockUserName", schema: "kraken", table: "ReleaseBatch");
migrationBuilder.AddForeignKey(
name: "FK_ReleaseBatchItem_ReleaseBatch_ReleaseBatchId",
schema: "kraken",
table: "ReleaseBatchItem",
column: "ReleaseBatchId",
principalSchema: "kraken",
principalTable: "ReleaseBatch",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_ReleaseBatchLogo_ReleaseBatch_ReleaseBatchId",
schema: "kraken",
table: "ReleaseBatchLogo",
column: "ReleaseBatchId",
principalSchema: "kraken",
principalTable: "ReleaseBatch",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
示例8: Down
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_OpeningHours_Shop_ShopId", table: "OpeningHours");
migrationBuilder.DropForeignKey(name: "FK_Prize_Shop_ShopId", table: "Prize");
migrationBuilder.DropForeignKey(name: "FK_Puzzle_Shop_ShopId", table: "Puzzle");
migrationBuilder.AddForeignKey(
name: "FK_OpeningHours_Shop_ShopId",
table: "OpeningHours",
column: "ShopId",
principalTable: "Shop",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_Prize_Shop_ShopId",
table: "Prize",
column: "ShopId",
principalTable: "Shop",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_Puzzle_Shop_ShopId",
table: "Puzzle",
column: "ShopId",
principalTable: "Shop",
principalColumn: "ID",
onDelete: ReferentialAction.Restrict);
}
示例9: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_Category_Article", table: "Article");
migrationBuilder.DropForeignKey(name: "FK_Section_Category", table: "Category");
migrationBuilder.AlterColumn<int>(
name: "SectionId",
table: "Section",
nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
migrationBuilder.AddColumn<bool>(
name: "IsDeleted",
table: "Section",
nullable: false,
defaultValue: false);
migrationBuilder.AddForeignKey(
name: "FK_Category_Article",
table: "Article",
column: "CategoryId",
principalTable: "Category",
principalColumn: "CategoryId",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Section_Category",
table: "Category",
column: "SectionId",
principalTable: "Section",
principalColumn: "SectionId",
onDelete: ReferentialAction.Cascade);
}
示例10: Down
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_MenuItem_Category_CategoryId", table: "MenuItem");
migrationBuilder.DropForeignKey(name: "FK_OrderItem_Order_OrderId", table: "OrderItem");
migrationBuilder.AlterColumn<int>(
name: "Id",
table: "OrderItem",
nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
migrationBuilder.AddColumn<decimal>(
name: "Total",
table: "Order",
nullable: false,
defaultValue: 0m);
migrationBuilder.AddForeignKey(
name: "FK_MenuItem_Category_CategoryId",
table: "MenuItem",
column: "CategoryId",
principalTable: "Category",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_OrderItem_Order_OrderId",
table: "OrderItem",
column: "OrderId",
principalTable: "Order",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
示例11: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "DisplayName",
table: "TestClasses",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_Commits_ProjectId",
table: "Commits",
column: "ProjectId");
migrationBuilder.CreateIndex(
name: "IX_Commits_UserId",
table: "Commits",
column: "UserId");
migrationBuilder.AddForeignKey(
name: "FK_Commits_Projects_ProjectId",
table: "Commits",
column: "ProjectId",
principalTable: "Projects",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Commits_Users_UserId",
table: "Commits",
column: "UserId",
principalTable: "Users",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
示例12: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_Category_Article", table: "Article");
migrationBuilder.AlterColumn<string>(
name: "Url",
table: "Section",
nullable: false);
migrationBuilder.AlterColumn<string>(
name: "Title",
table: "Section",
nullable: false);
migrationBuilder.AlterColumn<string>(
name: "Url",
table: "Category",
nullable: false);
migrationBuilder.AlterColumn<string>(
name: "Title",
table: "Category",
nullable: false);
migrationBuilder.AddForeignKey(
name: "FK_Category_Article",
table: "Article",
column: "CategoryId",
principalTable: "Category",
principalColumn: "CategoryId",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Section_Category",
table: "Category",
column: "SectionId",
principalTable: "Section",
principalColumn: "SectionId",
onDelete: ReferentialAction.Cascade);
}
示例13: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_Photo_Album_AlbumId", table: "Photo");
migrationBuilder.DropForeignKey(name: "FK_UserRole_Role_RoleId", table: "UserRole");
migrationBuilder.DropForeignKey(name: "FK_UserRole_User_UserId", table: "UserRole");
migrationBuilder.DropColumn(name: "Throwaway", table: "Album");
migrationBuilder.AddForeignKey(
name: "FK_Photo_Album_AlbumId",
table: "Photo",
column: "AlbumId",
principalTable: "Album",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_UserRole_Role_RoleId",
table: "UserRole",
column: "RoleId",
principalTable: "Role",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_UserRole_User_UserId",
table: "UserRole",
column: "UserId",
principalTable: "User",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
示例14: Up
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(name: "FK_Character_Planet_HomePlanetId", table: "Character");
migrationBuilder.CreateTable(
name: "Species",
columns: table => new
{
Id = table.Column<Guid>(nullable: false),
Description = table.Column<string>(nullable: true),
Name = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Species", x => x.Id);
});
migrationBuilder.AddColumn<Guid>(
name: "SpeciesId",
table: "Character",
nullable: true);
migrationBuilder.AddForeignKey(
name: "FK_Character_Planet_HomePlanetId",
table: "Character",
column: "HomePlanetId",
principalTable: "Planet",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Character_Species_SpeciesId",
table: "Character",
column: "SpeciesId",
principalTable: "Species",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
示例15: Up
protected override void Up(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.CreateTable(
name: "Event",
columns: table => new
{
ID = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
CompleteAddress = table.Column<string>(nullable: true),
EventEnd = table.Column<DateTime>(nullable: false),
EventStart = table.Column<DateTime>(nullable: false),
IsCurrent = table.Column<bool>(nullable: false),
Name = table.Column<string>(nullable: true),
SocialMediaHashtag = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Event", x => x.ID);
});
migrationBuilder.AddForeignKey(
name: "FK_IdentityRoleClaim<string>_IdentityRole_RoleId",
table: "AspNetRoleClaims",
column: "RoleId",
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_IdentityUserClaim<string>_ApplicationUser_UserId",
table: "AspNetUserClaims",
column: "UserId",
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_IdentityUserLogin<string>_ApplicationUser_UserId",
table: "AspNetUserLogins",
column: "UserId",
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_IdentityUserRole<string>_IdentityRole_RoleId",
table: "AspNetUserRoles",
column: "RoleId",
principalTable: "AspNetRoles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_IdentityUserRole<string>_ApplicationUser_UserId",
table: "AspNetUserRoles",
column: "UserId",
principalTable: "AspNetUsers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}