TenantCountryDm.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 TenantCountryDm : KeylessDm<TenantCountry>
  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<TenantCountry>(entity =>
  12. {
  13. entity.ToTable(Constants.Modules.Base.TblTenantCountry, Constants.Modules.Base.Schema);
  14. entity.HasKey(tu => new { tu.CountryId, tu.TenantId });
  15. // foreign keys
  16. entity.Property(e => e.TenantId).IsRequired()
  17. .HasComment("Reference to tenant that setting belongs");
  18. entity.Property(e => e.CountryId).IsRequired()
  19. .HasComment("Reference to country assigned to tenant");
  20. // relationships
  21. entity.HasOne(pc => pc.Tenant)
  22. .WithMany(p => p.Countries)
  23. .HasForeignKey(pc => pc.TenantId)
  24. .HasConstraintName("REL_TENANTCOUNTRY_TENANT_ID");
  25. entity.HasOne(pc => pc.Country)
  26. .WithMany(c => c.Tenants)
  27. .HasForeignKey(pc => pc.CountryId)
  28. .HasConstraintName("REL_TENANTCOUNTRY_COUNTRY_ID");
  29. }
  30. );
  31. }
  32. }
  33. }