Files
2026-07-21 14:14:44 +07:00

87 lines
2.9 KiB
C#

using Indotalent.Data.Entities;
using Indotalent.Shared.Consts;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Indotalent.Infrastructure.Database.MsSQL.Configuration;
public class CustomerConfiguration : IEntityTypeConfiguration<Customer>
{
public void Configure(EntityTypeBuilder<Customer> builder)
{
builder.Property(e => e.Name)
.HasMaxLength(GlobalConsts.StringLengthShort);
builder.Property(e => e.AutoNumber)
.HasMaxLength(GlobalConsts.StringLengthShort);
builder.Property(e => e.Description)
.HasMaxLength(GlobalConsts.StringLengthMedium);
builder.Property(e => e.Street)
.HasMaxLength(GlobalConsts.StringLengthShort);
builder.Property(e => e.City)
.HasMaxLength(GlobalConsts.StringLengthShort);
builder.Property(e => e.State)
.HasMaxLength(GlobalConsts.StringLengthShort);
builder.Property(e => e.ZipCode)
.HasMaxLength(GlobalConsts.StringLengthShort);
builder.Property(e => e.Country)
.HasMaxLength(GlobalConsts.StringLengthShort);
builder.Property(e => e.PhoneNumber)
.HasMaxLength(GlobalConsts.StringLengthShort);
builder.Property(e => e.FaxNumber)
.HasMaxLength(GlobalConsts.StringLengthShort);
builder.Property(e => e.EmailAddress)
.HasMaxLength(GlobalConsts.StringLengthShort);
builder.Property(e => e.Website)
.HasMaxLength(GlobalConsts.StringLengthShort);
builder.Property(e => e.WhatsApp)
.HasMaxLength(GlobalConsts.StringLengthShort);
builder.Property(e => e.LinkedIn)
.HasMaxLength(GlobalConsts.StringLengthShort);
builder.Property(e => e.Facebook)
.HasMaxLength(GlobalConsts.StringLengthShort);
builder.Property(e => e.Instagram)
.HasMaxLength(GlobalConsts.StringLengthShort);
builder.Property(e => e.TwitterX)
.HasMaxLength(GlobalConsts.StringLengthShort);
builder.Property(e => e.TikTok)
.HasMaxLength(GlobalConsts.StringLengthShort);
builder.Property(e => e.CustomerGroupId)
.HasMaxLength(GlobalConsts.StringLengthId);
builder.Property(e => e.CustomerCategoryId)
.HasMaxLength(GlobalConsts.StringLengthId);
builder.HasOne(e => e.CustomerGroup)
.WithMany()
.HasForeignKey(e => e.CustomerGroupId)
.OnDelete(DeleteBehavior.NoAction);
builder.HasOne(e => e.CustomerCategory)
.WithMany()
.HasForeignKey(e => e.CustomerCategoryId)
.OnDelete(DeleteBehavior.NoAction);
builder.HasIndex(e => new { e.TenantId, e.Name }).IsUnique();
builder.HasIndex(e => new { e.TenantId, e.AutoNumber }).IsUnique();
builder.HasIndex(e => e.CustomerGroupId);
builder.HasIndex(e => e.CustomerCategoryId);
}
}