当前位置: 首页>>代码示例>>C#>>正文


C# MigrationBuilder.AddForeignKey方法代码示例

本文整理汇总了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);
 }
开发者ID:OlsonDev,项目名称:PersonalWebApp,代码行数:25,代码来源:20160318190119_AddBlogTables.cs

示例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);
 }
开发者ID:bensgroi,项目名称:PhotoGallery,代码行数:31,代码来源:20160126215653_unused.cs

示例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);
        }
开发者ID:CSClassroom,项目名称:CSClassroom,代码行数:28,代码来源:20160923175252_Migration14.cs

示例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);
 }
开发者ID:isonaj,项目名称:portfolio2,代码行数:35,代码来源:20160221113610_3DecimalPrices.cs

示例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);
 }
开发者ID:ClairtonLopesJr,项目名称:LABS,代码行数:30,代码来源:20161120012824_tiposUsuario.cs

示例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);
 }
开发者ID:Zywave,项目名称:OctopusDeploy-Kraken,代码行数:26,代码来源:20160328171325_lockbatch.cs

示例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);
 }
开发者ID:sickpres,项目名称:PuzzleAdv,代码行数:27,代码来源:20160403132446_Puzzle8.cs

示例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);
 }
开发者ID:sergeyb12345,项目名称:MarketHunter,代码行数:29,代码来源:20151230124011_SectionIsDeleted.cs

示例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);
 }
开发者ID:hanjia2014,项目名称:HotmenuApp.rc1,代码行数:29,代码来源:20151124025524_OrderItemIdColumn.cs

示例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);
        }
开发者ID:CSClassroom,项目名称:CSClassroom,代码行数:33,代码来源:20160918231759_Migration9.cs

示例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);
 }
开发者ID:sergeyb12345,项目名称:MarketHunter,代码行数:34,代码来源:20151229104238_FkSectionCategory.cs

示例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);
 }
开发者ID:bensgroi,项目名称:PhotoGallery,代码行数:28,代码来源:20160126215653_unused.cs

示例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);
 }
开发者ID:freemsly,项目名称:MVC6-Awakens,代码行数:34,代码来源:20151205165231_Species.cs

示例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);
 }
开发者ID:desinole,项目名称:codecampster,代码行数:60,代码来源:20160130041403_addeventtable.cs


注:本文中的MigrationBuilder.AddForeignKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。