Skip to content

Commit

Permalink
Fix #2980 - Add cascade delete to foreign keys (#2982)
Browse files Browse the repository at this point in the history
  • Loading branch information
kbeaugrand authored May 3, 2024
1 parent 1877a57 commit 29bd29a
Show file tree
Hide file tree
Showing 7 changed files with 1,372 additions and 9 deletions.
14 changes: 11 additions & 3 deletions src/IoTHub.Portal.Infrastructure/PortalDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ public class PortalDbContext : DbContext, IDataProtectionKeyContext
public DbSet<Label> Labels { get; set; }
public DbSet<DataProtectionKey> DataProtectionKeys { get; set; }

#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
public PortalDbContext(DbContextOptions<PortalDbContext> options)
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
: base(options)
: base(options)
{
}

Expand Down Expand Up @@ -58,6 +56,16 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
.HasOne(x => x.DeviceModel)
.WithMany()
.HasForeignKey(x => x.DeviceModelId);

_ = modelBuilder.Entity<EdgeDevice>()
.HasMany(c => c.Tags)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);

_ = modelBuilder.Entity<Device>()
.HasMany(c => c.Tags)
.WithOne()
.OnDelete(DeleteBehavior.Cascade);
}
}
}
Loading

0 comments on commit 29bd29a

Please sign in to comment.