Files
components/LiteCharms.Features/Shop/ShoppingCarts/Entities/ShoppingCartItemConfiguration.cs
T
2026-05-13 20:06:24 +02:00

31 lines
1.1 KiB
C#

using LiteCharms.Features.Shop.Products.Entities;
namespace LiteCharms.Features.Shop.ShoppingCarts.Entities;
public class ShoppingCartItemConfiguration : IEntityTypeConfiguration<ShoppingCartItem>
{
public void Configure(EntityTypeBuilder<ShoppingCartItem> builder)
{
builder.ToTable(nameof(ShoppingCartItem));
builder.HasKey(f => f.Id);
builder.Property(f => f.CreatedAt).IsRequired().ValueGeneratedOnAdd().HasDefaultValueSql("now()");
builder.Property(f => f.UpdatedAt).IsRequired(false);
builder.Property(f => f.Quantity).IsRequired().HasDefaultValue(1);
builder.Property(f => f.ShoppingCartId).IsRequired();
builder.Property(f => f.ProductPriceId).IsRequired();
builder.HasOne<ShoppingCart>()
.WithMany(s => s.ShoppingCartItems)
.HasForeignKey(f => f.ShoppingCartId)
.IsRequired()
.OnDelete(DeleteBehavior.Cascade);
builder.HasOne<ProductPrice>()
.WithMany()
.HasForeignKey(f => f.ProductPriceId)
.IsRequired()
.OnDelete(DeleteBehavior.Restrict);
}
}