CountryDm.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Microsoft.EntityFrameworkCore;
  2. using Quadarax.Application.QLiberace.Common.Entities.Base.DaoMapper;
  3. namespace Quadarax.Application.QLiberace.Base.Entities.DaoMapper
  4. {
  5. public class CountryDm: TrackedDm<Country>
  6. {
  7. public override void Map(ModelBuilder builder)
  8. {
  9. if (builder == null) throw new ArgumentNullException(nameof(builder));
  10. base.Map(builder);
  11. builder.Entity<Country>(entity =>
  12. {
  13. entity.ToTable(Constants.Modules.Base.TblCountry, Constants.Modules.Base.Schema);
  14. // indexes
  15. entity.HasIndex(e => e.Code, "IDX_COUNTRY_CODE")
  16. .IsUnique();
  17. // columns
  18. entity.Property(e => e.Code).IsRequired()
  19. .HasMaxLength(5)
  20. .HasComment("Country code. Main key to search.");
  21. entity.Property(e => e.Name).IsRequired()
  22. .HasMaxLength(50)
  23. .HasComment("Country name. Informational value.");
  24. entity.Property(e => e.Vat).IsRequired()
  25. .HasDefaultValueSql("0")
  26. .HasComment("Percentage VAT definition");
  27. entity.Property(e => e.DefaultCurrencyId).IsRequired()
  28. .HasComment("Default country currency");
  29. // relationship
  30. entity.HasOne(d => d.DefaultCurrency)
  31. .WithMany(p => p.Countries)
  32. .HasForeignKey(d => d.DefaultCurrencyId)
  33. .OnDelete(DeleteBehavior.ClientSetNull)
  34. .HasConstraintName("REL_COUNTRY_CURRENCY_ID");
  35. }
  36. );
  37. }
  38. }
  39. }