This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user