using Quadarax.Application.QLiberace.Common.Entities.Base.DaoMapper; using Microsoft.EntityFrameworkCore; namespace Quadarax.Application.QLiberace.Base.Entities.DaoMapper { public class TenantUserDm : KeylessDm { public override void Map(ModelBuilder builder) { if (builder == null) throw new ArgumentNullException(nameof(builder)); base.Map(builder); builder.Entity(entity => { entity.ToTable(Constants.Modules.Base.TblTenantUser, Constants.Modules.Base.Schema); entity.HasKey(tu => new { tu.UserId, tu.TenantId }); // foreign keys entity.Property(e => e.TenantId).IsRequired() .HasComment("Reference to tenant that setting belongs"); entity.Property(e => e.UserId).IsRequired() .HasComment("Reference to user assigned to tenant"); // relationships entity.HasOne(pc => pc.Tenant) .WithMany(p => p.Users) .HasForeignKey(pc => pc.TenantId) .HasConstraintName("REL_TENANTUSER_TENANT_ID"); entity.HasOne(pc => pc.User) .WithMany(c => c.Tenants) .HasForeignKey(pc => pc.UserId) .HasConstraintName("REL_TENANTUSER_USER_ID"); } ); } } }