ContactDm.cs 2.6 KB

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