32 lines
1.2 KiB
C#
32 lines
1.2 KiB
C#
namespace LiteCharms.Entities.Configuration;
|
|
|
|
public class ShoppingCartConfiguration : IEntityTypeConfiguration<ShoppingCart>
|
|
{
|
|
public void Configure(EntityTypeBuilder<ShoppingCart> builder)
|
|
{
|
|
builder.ToTable(nameof(ShoppingCart));
|
|
|
|
builder.HasKey(f => f.Id);
|
|
builder.Property(f => f.CreatedAt).IsRequired().ValueGeneratedOnAdd();
|
|
builder.Property(f => f.UpdatedAt).IsRequired(false).ValueGeneratedOnUpdate();
|
|
builder.Property(f => f.CustomerId).IsRequired(false);
|
|
builder.Property(f => f.OrderId).IsRequired(false);
|
|
builder.Property(f => f.QuoteId).IsRequired(false);
|
|
|
|
builder.HasOne(f => f.Customer)
|
|
.WithMany(c => c.ShoppingCarts)
|
|
.HasForeignKey(f => f.CustomerId)
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
builder.HasOne(f => f.Order)
|
|
.WithOne(o => o.ShoppingCart)
|
|
.HasForeignKey<Order>(o => o.ShoppingCartId)
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
builder.HasOne(f => f.Quote)
|
|
.WithOne(o => o.ShoppingCart)
|
|
.HasForeignKey<Quote>(o => o.ShoppingCartId)
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
}
|
|
}
|