ContactDm.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Microsoft.EntityFrameworkCore;
  2. using Quadarax.Application.QLiberace.Base;
  3. using Quadarax.Application.QLiberace.Common.Entities.Base.DaoMapper;
  4. using Quadarax.Application.QLiberace.Customer.Enums;
  5. namespace Quadarax.Application.QLiberace.Customer.Entities.DaoMapper
  6. {
  7. public class ContactDm : TrackedDm<Contact>
  8. {
  9. public override void Map(ModelBuilder builder)
  10. {
  11. if (builder == null) throw new ArgumentNullException(nameof(builder));
  12. base.Map(builder);
  13. builder.Entity<Contact>(entity =>
  14. {
  15. entity.ToTable(Constants.Modules.Customer.TblContact, Constants.Modules.Customer.Schema);
  16. entity.Property(e => e.Address).IsRequired()
  17. .HasMaxLength(100)
  18. .HasComment("Main address value. If phone, email, sms stores email address or telephone number.");
  19. entity.Property(e => e.Address1)
  20. .HasMaxLength(100)
  21. .HasComment("Secondary address value.");
  22. entity.Property(e => e.Caption).IsRequired()
  23. .HasMaxLength(100)
  24. .HasComment("Contact heading caption.");
  25. entity.Property(e => e.City)
  26. .HasMaxLength(50)
  27. .HasComment("Contact city.");
  28. entity.Property(e => e.CountryCode)
  29. .HasMaxLength(5)
  30. .HasComment("Contact country code.");
  31. entity.Property(e => e.CustomerId).IsRequired()
  32. .HasComment("Reference to customer that contact belongs");
  33. entity.Property(e => e.IsPreferred).IsRequired()
  34. .HasDefaultValueSql("0")
  35. .HasComment("Flag if Contact is preffered.");
  36. entity.Property(e => e.Type).IsRequired()
  37. .HasDefaultValueSql("0")
  38. .HasComment("Contact type (0-Email, 1-Address, 2-Phone, 3-SMS)")
  39. .HasConversion<int>();
  40. entity.Property(e => e.Zip)
  41. .HasMaxLength(20)
  42. .HasColumnName("ZIP")
  43. .HasComment("Contact ZIP code.");
  44. // relationships
  45. entity.HasOne(d => d.Customer)
  46. .WithMany(p => p.Contacts)
  47. .HasForeignKey(d => d.CustomerId)
  48. .OnDelete(DeleteBehavior.NoAction)
  49. .HasConstraintName("REL_CONTACT_CUSTOMER_ID");
  50. }
  51. );
  52. }
  53. }
  54. }