TenantCurrencyDm.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 TenantCurrencyDm : KeylessDm<TenantCurrency>
  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<TenantCurrency>(entity =>
  12. {
  13. entity.ToTable(Constants.Modules.Base.TblTenantCurrency, Constants.Modules.Base.Schema);
  14. entity.HasKey(tu => new { tu.CurerrencyId, 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.CurerrencyId).IsRequired()
  19. .HasComment("Reference to currency assigned to tenant");
  20. // relationships
  21. entity.HasOne(pc => pc.Tenant)
  22. .WithMany(p => p.Currencies)
  23. .HasForeignKey(pc => pc.TenantId)
  24. .HasConstraintName("REL_TENANTCURRENCY_TENANT_ID");
  25. entity.HasOne(pc => pc.Currency)
  26. .WithMany(c => c.Tenants)
  27. .HasForeignKey(pc => pc.CurerrencyId)
  28. .HasConstraintName("REL_TENANTCURRENCY_CURRENCY_ID");
  29. }
  30. );
  31. }
  32. }
  33. }