Files
components/LiteCharms.Features.TechShop/ShoppingCarts/Entities/ShoppingCartConfiguration.cs
T
Khwezi Mngoma 70c6e0bfbc
continuous-integration/drone/pr Build is passing
Split Features to create space for more projects
2026-05-24 13:19:09 +02:00

27 lines
991 B
C#

namespace LiteCharms.Features.TechShop.ShoppingCarts.Entities;
public class ShoppingCartConfiguration : IEntityTypeConfiguration<ShoppingCart>
{
public void Configure(EntityTypeBuilder<ShoppingCart> builder)
{
builder.ToTable("ShoppingCarts");
builder.HasKey(f => f.Id);
builder.Property(f => f.CreatedAt).IsRequired().ValueGeneratedOnAdd().HasDefaultValueSql("now()");
builder.Property(f => f.UpdatedAt).IsRequired(false).HasDefaultValueSql(null);
builder.Property(f => f.CustomerId).IsRequired();
builder.Property(f => f.OrderId);
builder.HasOne(s => s.Customer)
.WithMany(c => c.ShoppingCarts)
.HasForeignKey(s => s.CustomerId)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade);
builder.HasOne(s => s.Order)
.WithOne(o => o.ShoppingCart)
.HasForeignKey<ShoppingCart>(s => s.OrderId)
.OnDelete(DeleteBehavior.SetNull);
}
}