using Microsoft.EntityFrameworkCore; using Quadarax.Application.QLiberace.Common.Entities.Base.DaoMapper; namespace Quadarax.Application.QLiberace.Base.Entities.DaoMapper { public class TenantCountryDm : KeylessDm { 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.TblTenantCountry, Constants.Modules.Base.Schema); entity.HasKey(tu => new { tu.CountryId, tu.TenantId }); // foreign keys entity.Property(e => e.TenantId).IsRequired() .HasComment("Reference to tenant that setting belongs"); entity.Property(e => e.CountryId).IsRequired() .HasComment("Reference to country assigned to tenant"); // relationships entity.HasOne(pc => pc.Tenant) .WithMany(p => p.Countries) .HasForeignKey(pc => pc.TenantId) .HasConstraintName("REL_TENANTCOUNTRY_TENANT_ID"); entity.HasOne(pc => pc.Country) .WithMany(c => c.Tenants) .HasForeignKey(pc => pc.CountryId) .HasConstraintName("REL_TENANTCOUNTRY_COUNTRY_ID"); } ); } } }