902942eee6
continuous-integration/drone/pr Build is passing
Sealed qualifying public classes Migrated database changes
34 lines
1.3 KiB
C#
34 lines
1.3 KiB
C#
namespace LiteCharms.Features.MidrandBooks.Orders.Entities;
|
|
|
|
public sealed class ShippingConfiguration : IEntityTypeConfiguration<Shipping>
|
|
{
|
|
public void Configure(EntityTypeBuilder<Shipping> builder)
|
|
{
|
|
builder.ToTable("Shippings");
|
|
|
|
builder.HasKey(s => s.Id);
|
|
builder.Property(s => s.OrderId).IsRequired();
|
|
builder.Property(s => s.AddressId).IsRequired();
|
|
builder.Property(s => s.ShippingProviderId).IsRequired();
|
|
builder.Property(s => s.CreatedAt).IsRequired().ValueGeneratedOnAdd().HasDefaultValueSql("now()");
|
|
builder.Property(s => s.UpdatedAt).HasDefaultValueSql("now()");
|
|
builder.Property(s => s.Status).IsRequired();
|
|
builder.Property(s => s.TrackingNumber).HasMaxLength(255);
|
|
|
|
builder.HasOne(s => s.Order)
|
|
.WithOne(o => o.Shipping)
|
|
.HasForeignKey<Shipping>(s => s.OrderId)
|
|
.OnDelete(DeleteBehavior.Restrict);
|
|
|
|
builder.HasOne(s => s.Address)
|
|
.WithMany()
|
|
.HasForeignKey(s => s.AddressId)
|
|
.OnDelete(DeleteBehavior.Restrict);
|
|
|
|
builder.HasOne(f => f.ShippingProvider)
|
|
.WithMany(f => f.Shippings)
|
|
.HasForeignKey(f => f.ShippingProviderId)
|
|
.OnDelete(DeleteBehavior.Restrict);
|
|
}
|
|
}
|