using Indotalent.Data.Entities; using Indotalent.Shared.Consts; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Indotalent.Infrastructure.Database.MsSQL.Configuration; public class SalesOrderConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.Property(e => e.AutoNumber) .HasMaxLength(GlobalConsts.StringLengthShort); builder.Property(e => e.Description) .HasMaxLength(GlobalConsts.StringLengthMedium); builder.Property(e => e.CustomerId) .HasMaxLength(GlobalConsts.StringLengthId); builder.Property(e => e.TaxId) .HasMaxLength(GlobalConsts.StringLengthId); builder.Property(e => e.SalesOrderGroupId) .HasMaxLength(GlobalConsts.StringLengthId); builder.Property(e => e.SalesOrderCategoryId) .HasMaxLength(GlobalConsts.StringLengthId); builder.HasOne(e => e.Customer) .WithMany() .HasForeignKey(e => e.CustomerId) .OnDelete(DeleteBehavior.NoAction); builder.HasOne(e => e.Employee) .WithMany() .HasForeignKey(e => e.EmployeeId) .OnDelete(DeleteBehavior.NoAction); builder.HasOne(e => e.Tax) .WithMany() .HasForeignKey(e => e.TaxId) .OnDelete(DeleteBehavior.NoAction); builder.HasOne(e => e.SalesOrderGroup) .WithMany() .HasForeignKey(e => e.SalesOrderGroupId) .OnDelete(DeleteBehavior.NoAction); builder.HasOne(e => e.SalesOrderCategory) .WithMany() .HasForeignKey(e => e.SalesOrderCategoryId) .OnDelete(DeleteBehavior.NoAction); builder.HasMany(e => e.SalesOrderItemList) .WithOne(e => e.SalesOrder) .HasForeignKey(e => e.SalesOrderId) .OnDelete(DeleteBehavior.NoAction); builder.HasIndex(e => e.AutoNumber).IsUnique(); builder.HasIndex(e => e.OrderDate); builder.HasIndex(e => e.CustomerId); builder.HasIndex(e => e.TaxId); builder.HasIndex(e => e.EmployeeId); } }