| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using Microsoft.EntityFrameworkCore;
- using Quadarax.Application.QLiberace.Base;
- using Quadarax.Application.QLiberace.Common.Entities.Base.DaoMapper;
- using Quadarax.Application.QLiberace.Customer.Enums;
- namespace Quadarax.Application.QLiberace.Customer.Entities.DaoMapper
- {
- public class ContactDm : TrackedDm<Contact>
- {
- public override void Map(ModelBuilder builder)
- {
- if (builder == null) throw new ArgumentNullException(nameof(builder));
- base.Map(builder);
- builder.Entity<Contact>(entity =>
- {
- entity.ToTable(Constants.Modules.Customer.TblContact, Constants.Modules.Customer.Schema);
- entity.Property(e => e.Address).IsRequired()
- .HasMaxLength(100)
- .HasComment("Main address value. If phone, email, sms stores email address or telephone number.");
- entity.Property(e => e.Address1)
- .HasMaxLength(100)
- .HasComment("Secondary address value.");
- entity.Property(e => e.Caption).IsRequired()
- .HasMaxLength(100)
- .HasComment("Contact heading caption.");
- entity.Property(e => e.City)
- .HasMaxLength(50)
- .HasComment("Contact city.");
- entity.Property(e => e.CountryCode)
- .HasMaxLength(5)
- .HasComment("Contact country code.");
-
- entity.Property(e => e.CustomerId).IsRequired()
- .HasComment("Reference to customer that contact belongs");
- entity.Property(e => e.IsPreferred).IsRequired()
- .HasDefaultValueSql("0")
- .HasComment("Flag if Contact is preffered.");
-
- entity.Property(e => e.Type).IsRequired()
- .HasDefaultValueSql("0")
- .HasComment("Contact type (0-Email, 1-Address, 2-Phone, 3-SMS)")
- .HasConversion<int>();
- entity.Property(e => e.Zip)
- .HasMaxLength(20)
- .HasColumnName("ZIP")
- .HasComment("Contact ZIP code.");
-
- // relationships
- entity.HasOne(d => d.Customer)
- .WithMany(p => p.Contacts)
- .HasForeignKey(d => d.CustomerId)
- .OnDelete(DeleteBehavior.NoAction)
- .HasConstraintName("REL_CONTACT_CUSTOMER_ID");
- }
- );
- }
- }
- }
|