beziehuing

This commit is contained in:
Tizian.Breuch
2025-09-08 11:28:05 +02:00
parent b3d459f67c
commit 88a81aa795

View File

@@ -171,6 +171,21 @@ namespace Webshop.Infrastructure.Data
.HasForeignKey(cd => cd.DiscountId); .HasForeignKey(cd => cd.DiscountId);
}); });
modelBuilder.Entity<Review>(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
});
} }
} }