Explorar el Código

Add TenantUserDm, fixup mappings (working)

Dalibor Votruba hace 3 años
padre
commit
abf5cb8c7e

+ 20 - 0
Common/qdr.app.qlbrc.common/Entities/Base/DaoMapper/KeylessDm.cs

@@ -0,0 +1,20 @@
+using Microsoft.EntityFrameworkCore;
+using Quadarax.Foundation.Core.Data.Entity;
+
+namespace Quadarax.Application.QLiberace.Common.Entities.Base.DaoMapper
+{
+    public class KeylessDm<TEntity> : AbstractDaoMapper where TEntity : QlbrcEntityKeyless
+    {
+        public override void Map(ModelBuilder builder)
+        {
+            if (builder == null) throw new ArgumentNullException(nameof(builder));
+
+            builder.Entity<TEntity>(entity =>
+                {
+                    entity.HasNoKey();
+                }
+            );
+
+        }
+    }
+}

+ 0 - 1
Common/qdr.app.qlbrc.common/Entities/Base/QlbrcEntityTenant.cs

@@ -6,7 +6,6 @@ namespace Quadarax.Application.QLiberace.Common.Entities.Base
 {
     public abstract class QlbrcEntityTenant : QlbrcEntityTracked, ITenant
     {
-        [ForeignKey("FK_Tenant_Id")]
         public long TenantId { get; set; }
     }
 }

+ 39 - 0
Modules/qdr.app.qlbrc.base/Entities/DaoMapper/TenantUserDm.cs

@@ -0,0 +1,39 @@
+using Quadarax.Application.QLiberace.Common.Entities.Base.DaoMapper;
+using Microsoft.EntityFrameworkCore;
+
+namespace Quadarax.Application.QLiberace.Base.Entities.DaoMapper
+{
+    public class TenantUserDm : KeylessDm<TenantUser>
+    {
+        public override void Map(ModelBuilder builder)
+        {
+
+            if (builder == null) throw new ArgumentNullException(nameof(builder));
+
+            base.Map(builder);
+            builder.Entity<TenantUser>(entity =>
+                {
+                    entity.ToTable(Constants.Modules.Base.TblTenantUser, Constants.Modules.Base.Schema);
+
+                    // 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(d => d.Tenant)
+                        .WithMany()
+                        .HasForeignKey(d => d.TenantId)
+                        .HasConstraintName("REL_TENANTUSER_TENANT_ID");
+
+                    entity.HasOne(d => d.User)
+                        .WithMany()
+                        .HasForeignKey(d => d.UserId)
+                        .HasConstraintName("REL_TENANTUSER_USER_ID");
+
+                }
+            );
+        }
+    }
+}

+ 0 - 15
Modules/qdr.app.qlbrc.base/Entities/Setting.cs

@@ -7,34 +7,19 @@ using Microsoft.EntityFrameworkCore;
 using Quadarax.Foundation.Core.Reflection;
 namespace Quadarax.Application.QLiberace.Base.Entities;
 
-[Table(Constants.Modules.Base.TblSetting,Schema = Constants.Modules.Base.Schema)]
-[Index("TenantId", "ModuleCode","Code", Name="IDX_CODE_TENANTMODULECODE", IsUnique = true )]
 public class Setting : QlbrcEntityTenant, IStructSetting
 {
     #region *** Properties ***
-    [ForeignKey("FK_Setting_Parent_Id")]
     public long? ParentId { get; set; }
-    [Required]
-    [DefaultValue(0)]
     public int SequenceNo { get; set; }
-    [MaxLength(10)]
-    [Required(AllowEmptyStrings = false)]
     public string ModuleCode { get; set; } = null!;
 
-    [MaxLength(100)]
-    [Required(AllowEmptyStrings = false)]
     public string Code { get; set; } = null!;
 
-    [MaxLength(500)]
     public string? Description { get; set; }
 
-    [MaxLength(500)]
-    [Required(AllowEmptyStrings = false)]
     public string ValueTypeQualified { get; set; } = null!;
-    [MaxLength(5000)]
     public string? Value { get; set; }
-    [Required]
-    [DefaultValue(false)]
     public bool IsEnabled { get; set; }
     #endregion
 

+ 1 - 10
Modules/qdr.app.qlbrc.base/Entities/Tenant.cs

@@ -6,29 +6,20 @@ using System.ComponentModel.DataAnnotations.Schema;
 
 namespace Quadarax.Application.QLiberace.Base.Entities
 {
-    [Table(Constants.Modules.Base.TblTenant,Schema = Constants.Modules.Base.Schema)]
-    [Index("Code", Name="IDX_TENANT_CODE", IsUnique = true )]
     public class Tenant : QlbrcEntityTracked, IStructTenant
     {
-        [MaxLength(20)]
-        [Required(AllowEmptyStrings =false)]
         public string Code { get; set; } = null!;
 
-        [MaxLength(200)]
-        [Required(AllowEmptyStrings =false)]
         public string Name { get; set; } = null!;
 
         public DateTime? LastAccess { get; set; }
-        [Required]
         public bool IsLocked { get; set; }
 
-        [NotMapped]
-        public virtual ICollection<TenantUser> Users { get; set; }
+        
 
 
         public Tenant()
         {
-            Users = new List<TenantUser>();
         }
 
     }

+ 2 - 11
Modules/qdr.app.qlbrc.base/Entities/TenantUser.cs

@@ -1,25 +1,16 @@
-using System.ComponentModel.DataAnnotations.Schema;
-using Microsoft.EntityFrameworkCore;
-using Quadarax.Application.QLiberace.Common.Entities.Base;
+using Quadarax.Application.QLiberace.Common.Entities.Base;
 
 
 namespace Quadarax.Application.QLiberace.Base.Entities
 {
-    [Table(Constants.Modules.Base.TblTenantUser,Schema = Constants.Modules.Base.Schema)]
-    [Index("UserId", "TenantId", Name="IDX_USER_TENANT_ID", IsUnique = true )]
-    [Keyless]
+    
     public class TenantUser : QlbrcEntityKeyless
     {
-        [Column(Order = 1)]
         public long UserId { get; set; }
 
-        [Column(Order = 2)]
         public long TenantId { get; set; }
 
-
-        [ForeignKey("UserId")]        
         public User User { get; set; } = null!;
-        [ForeignKey("TenantId")]        
         public Tenant Tenant { get; set; } = null!;
     }
 }

+ 1 - 14
Modules/qdr.app.qlbrc.base/Entities/User.cs

@@ -1,30 +1,17 @@
-using System.ComponentModel;
-using System.ComponentModel.DataAnnotations;
-using Quadarax.Application.QLiberace.Base.Entities.Interfaces;
+using Quadarax.Application.QLiberace.Base.Entities.Interfaces;
 using Quadarax.Application.QLiberace.Common.Entities.Base;
-using System.ComponentModel.DataAnnotations.Schema;
-using Microsoft.EntityFrameworkCore;
 
 namespace Quadarax.Application.QLiberace.Base.Entities
 {
-    [Table(Constants.Modules.Base.TblUser,Schema = Constants.Modules.Base.Schema)]
-    [Index("LoginName", Name="IDX_LOGIN_NAME", IsUnique = true )]
     public class User : QlbrcEntityTracked, IStructUser
     {
-        [MaxLength(100)]
-        [Required(AllowEmptyStrings = false)]
         public string LoginName { get; set; } = null!;
 
-        [Required]
-        [DefaultValue(false)]
         public bool IsLocked { get; set; }
 
-        [NotMapped]
-        public virtual ICollection<TenantUser> Tenants { get; set; }
 
         public User()
         {
-            Tenants = new List<TenantUser>();
         }
 
     }

+ 1 - 0
Modules/qdr.app.qlbrc.base/QlbrcDbContext.cs

@@ -52,6 +52,7 @@ namespace Quadarax.Application.QLiberace.Base
             new TenantDm().Map(modelBuilder);
             new UserDm().Map(modelBuilder);
             new SettingDm().Map(modelBuilder);
+            new TenantUserDm().Map(modelBuilder);
 
             base.OnModelCreating(modelBuilder);
         }