Cascade delete keys on game deletion

dashboard
Pat Hartl 2023-01-09 18:55:50 -06:00
parent ed83489683
commit 730c8364e8
4 changed files with 1067 additions and 3 deletions

View File

@ -36,12 +36,14 @@ namespace LANCommander.Data
builder.Entity<Game>()
.HasMany(g => g.Archives)
.WithOne(g => g.Game)
.IsRequired(false);
.IsRequired(true)
.OnDelete(DeleteBehavior.Cascade);
builder.Entity<Game>()
.HasMany(g => g.Keys)
.WithOne(g => g.Game)
.IsRequired(false);
.IsRequired(true)
.OnDelete(DeleteBehavior.Cascade);
builder.Entity<Game>()
.HasMany(g => g.Actions)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,38 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace LANCommander.Migrations
{
public partial class CascadeGameKeyDeletion : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Keys_Games_GameId",
table: "Keys");
migrationBuilder.AddForeignKey(
name: "FK_Keys_Games_GameId",
table: "Keys",
column: "GameId",
principalTable: "Games",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Keys_Games_GameId",
table: "Keys");
migrationBuilder.AddForeignKey(
name: "FK_Keys_Games_GameId",
table: "Keys",
column: "GameId",
principalTable: "Games",
principalColumn: "Id");
}
}
}

View File

@ -893,7 +893,9 @@ namespace LANCommander.Migrations
b.HasOne("LANCommander.Data.Models.Game", "Game")
.WithMany("Keys")
.HasForeignKey("GameId");
.HasForeignKey("GameId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("LANCommander.Data.Models.User", "UpdatedBy")
.WithMany()