CustomerUserDm.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using Quadarax.Application.QLiberace.Common.Entities.Base.DaoMapper;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Microsoft.EntityFrameworkCore;
  8. using Quadarax.Application.QLiberace.Base;
  9. namespace Quadarax.Application.QLiberace.Customer.Entities.DaoMapper
  10. {
  11. internal class CustomerUserDm : KeylessDm<CustomerUser>
  12. {
  13. public override void Map(ModelBuilder builder)
  14. {
  15. if (builder == null) throw new ArgumentNullException(nameof(builder));
  16. base.Map(builder);
  17. builder.Entity<CustomerUser>(entity =>
  18. {
  19. entity.ToTable(Constants.Modules.Customer.TblCustomerUser, Constants.Modules.Customer.Schema);
  20. entity.HasKey(tu => new { tu.CustomerId, tu.UserLoginName });
  21. entity.Property(e => e.CustomerId).IsRequired()
  22. .HasComment("Reference to customer");
  23. entity.Property(e => e.UserLoginName).IsRequired()
  24. .HasMaxLength(100)
  25. .HasComment("Reference to user");
  26. // relationships
  27. entity.HasOne(pc => pc.Customer)
  28. .WithMany(p => p.Users)
  29. .HasForeignKey(pc => pc.CustomerId)
  30. .OnDelete(DeleteBehavior.NoAction)
  31. .HasConstraintName("REL_CUSTOMERUSER_CUSTOMER_ID");
  32. }
  33. );
  34. }
  35. }
  36. }