TenantUserDm.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using Quadarax.Application.QLiberace.Common.Entities.Base.DaoMapper;
  2. using Microsoft.EntityFrameworkCore;
  3. namespace Quadarax.Application.QLiberace.Base.Entities.DaoMapper
  4. {
  5. public class TenantUserDm : KeylessDm<TenantUser>
  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<TenantUser>(entity =>
  12. {
  13. entity.ToTable(Constants.Modules.Base.TblTenantUser, Constants.Modules.Base.Schema);
  14. entity.HasKey(tu => new { tu.UserId, tu.TenantId });
  15. // foreign keys
  16. entity.Property(e => e.TenantId).IsRequired()
  17. .HasComment("Reference to tenant that setting belongs");
  18. entity.Property(e => e.UserId).IsRequired()
  19. .HasComment("Reference to user assigned to tenant");
  20. // relationships
  21. entity.HasOne(pc => pc.Tenant)
  22. .WithMany(p => p.Users)
  23. .HasForeignKey(pc => pc.TenantId)
  24. .HasConstraintName("REL_TENANTUSER_TENANT_ID");
  25. entity.HasOne(pc => pc.User)
  26. .WithMany(c => c.Tenants)
  27. .HasForeignKey(pc => pc.UserId)
  28. .HasConstraintName("REL_TENANTUSER_USER_ID");
  29. }
  30. );
  31. }
  32. }
  33. }