From 88a81aa795e71cd26817c1afa4cc30a3961d16bf Mon Sep 17 00:00:00 2001 From: "Tizian.Breuch" Date: Mon, 8 Sep 2025 11:28:05 +0200 Subject: [PATCH] beziehuing --- .../Data/ApplicationDbContext.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Webshop.Infrastructure/Data/ApplicationDbContext.cs b/Webshop.Infrastructure/Data/ApplicationDbContext.cs index 04888a4..dd74cac 100644 --- a/Webshop.Infrastructure/Data/ApplicationDbContext.cs +++ b/Webshop.Infrastructure/Data/ApplicationDbContext.cs @@ -171,6 +171,21 @@ namespace Webshop.Infrastructure.Data .HasForeignKey(cd => cd.DiscountId); }); + modelBuilder.Entity(entity => + { + // Beziehung zu Product + entity.HasOne(r => r.Product) + .WithMany(p => p.Reviews) + .HasForeignKey(r => r.ProductId) + .OnDelete(DeleteBehavior.Cascade); // Lösche Bewertungen, wenn das Produkt gelöscht wird + + // Beziehung zu Customer + entity.HasOne(r => r.Customer) + .WithMany(c => c.Reviews) + .HasForeignKey(r => r.CustomerId) + .OnDelete(DeleteBehavior.SetNull); // Setze CustomerId auf NULL, wenn der Kunde gelöscht wird + }); + } }