beziehuing
This commit is contained in:
@@ -171,6 +171,21 @@ namespace Webshop.Infrastructure.Data
|
||||
.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
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user