| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using Microsoft.EntityFrameworkCore;
- using Quadarax.Application.QLiberace.Common.Entities.Base.DaoMapper;
- namespace Quadarax.Application.QLiberace.Base.Entities.DaoMapper
- {
- public class CountryDm: TrackedDm<Country>
- {
- public override void Map(ModelBuilder builder)
- {
- if (builder == null) throw new ArgumentNullException(nameof(builder));
- base.Map(builder);
- builder.Entity<Country>(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");
- }
- );
- }
- }
- }
|