using Microsoft.EntityFrameworkCore; using Quadarax.Application.QLiberace.Common.Entities.Base.DaoMapper; namespace Quadarax.Application.QLiberace.Base.Entities.DaoMapper { public class CountryDm: TrackedDm { public override void Map(ModelBuilder builder) { if (builder == null) throw new ArgumentNullException(nameof(builder)); base.Map(builder); builder.Entity(entity => { entity.ToTable(Constants.Modules.Base.TblCountry, Constants.Modules.Base.Schema); // indexes entity.HasIndex(e => e.Code, "IDX_COUNTRY_CODE") .IsUnique(); // columns entity.Property(e => e.Code).IsRequired() .HasMaxLength(5) .HasComment("Country code. Main key to search."); entity.Property(e => e.Name).IsRequired() .HasMaxLength(50) .HasComment("Country name. Informational value."); entity.Property(e => e.Vat).IsRequired() .HasDefaultValueSql("0") .HasComment("Percentage VAT definition"); entity.Property(e => e.DefaultCurrencyId).IsRequired() .HasComment("Default country currency"); // relationship entity.HasOne(d => d.DefaultCurrency) .WithMany(p => p.Countries) .HasForeignKey(d => d.DefaultCurrencyId) .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("REL_COUNTRY_CURRENCY_ID"); } ); } } }