SettingDm.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Microsoft.EntityFrameworkCore;
  2. using Quadarax.Application.QLiberace.Common.Entities.Base.DaoMapper;
  3. namespace Quadarax.Application.QLiberace.Base.Entities.DaoMapper
  4. {
  5. internal class SettingDm : TrackedDm<Setting>
  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<Setting>(entity =>
  12. {
  13. entity.ToTable(Constants.Modules.Base.TblSetting, Constants.Modules.Base.Schema);
  14. // indexes
  15. entity.HasIndex(e => new { e.TenantId, e.ModuleCode, e.Code }, "IDX_SETTING_TENANT_MCODE_CODE")
  16. .IsUnique();
  17. // foreign keys
  18. entity.Property(e => e.TenantId).IsRequired().HasComment("Reference to tenant that setting belongs");
  19. entity.Property(e => e.ParentId).HasComment("Reference to parent setting");
  20. // columns
  21. entity.Property(e => e.Code).IsRequired()
  22. .HasMaxLength(100)
  23. .HasComment("Setting code. Main key to search.");
  24. entity.Property(e => e.Description)
  25. .HasMaxLength(500)
  26. .HasComment("Setting value description");
  27. entity.Property(e => e.IsEnabled).IsRequired()
  28. .HasDefaultValueSql("0").HasComment("Flag if setting is enabled");
  29. entity.Property(e => e.ModuleCode).IsRequired()
  30. .HasMaxLength(10)
  31. .HasComment("Module code that setting belongs. Secondary key");
  32. entity.Property(e => e.SequenceNo).IsRequired()
  33. .HasDefaultValueSql("0")
  34. .HasComment("Order number");
  35. entity.Property(e => e.Value)
  36. .HasComment("Setting value");
  37. entity.Property(e => e.ValueTypeQualified).IsRequired()
  38. .HasMaxLength(500)
  39. .HasComment("Qualified name of value type");
  40. /*
  41. entity.HasOne(d => d.Parent)
  42. .WithMany(p => p.InverseParent)
  43. .HasForeignKey(d => d.ParentId)
  44. .HasConstraintName("REL_SETTING_SETTING_ID");
  45. entity.HasOne(d => d.Tenant)
  46. .WithMany(p => p.Settings)
  47. .HasForeignKey(d => d.TenantId)
  48. .OnDelete(DeleteBehavior.ClientSetNull)
  49. .HasConstraintName("REL_SETTING_TENANT_ID");
  50. */
  51. }
  52. );
  53. }
  54. }
  55. }