using System; using System.Collections.Generic; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; namespace Workbench.Entity { public partial class QLiberaceContext : DbContext { public QLiberaceContext() { } public QLiberaceContext(DbContextOptions options) : base(options) { } public virtual DbSet Settings { get; set; } = null!; public virtual DbSet Tenants { get; set; } = null!; public virtual DbSet TenantUsers { get; set; } = null!; public virtual DbSet Users { get; set; } = null!; protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) { #warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263. optionsBuilder.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Database=QLiberace;Trusted_Connection=True;"); } } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => { entity.ToTable("Setting", "base"); entity.HasIndex(e => new { e.TenantId, e.ModuleCode, e.Code }, "IDX_SETTING_TENANT_MCODE_CODE") .IsUnique(); entity.Property(e => e.Id).HasComment("Setting primary key"); entity.Property(e => e.Code) .HasMaxLength(100) .HasComment("Setting code. Main key to search."); entity.Property(e => e.Created) .HasColumnType("datetime") .HasDefaultValueSql("(getdate())") .HasComment("Record created timestamp"); entity.Property(e => e.Description) .HasMaxLength(500) .HasComment("Setting value description"); entity.Property(e => e.IsEnabled).HasComment("Flag if setting is enabled"); entity.Property(e => e.Modified) .HasColumnType("datetime") .HasComment("Record modified timestamp"); entity.Property(e => e.Modifier) .HasMaxLength(100) .HasComment("Record modifier signature"); entity.Property(e => e.ModuleCode) .HasMaxLength(10) .HasComment("Module code that setting belongs. Secondary key"); entity.Property(e => e.Name) .HasMaxLength(200) .HasComment("Setting name. Informational value."); entity.Property(e => e.ParentId).HasComment("Reference to parent setting"); entity.Property(e => e.SequenceNo).HasComment("Order number"); entity.Property(e => e.TenantId).HasComment("Reference to tenant that setting belongs"); entity.Property(e => e.Value).HasComment("Setting value"); entity.Property(e => e.ValueTypeQualified) .HasMaxLength(500) .HasComment("Qualified name of value type"); entity.HasOne(d => d.Parent) .WithMany(p => p.InverseParent) .HasForeignKey(d => d.ParentId) .HasConstraintName("REL_SETTING_SETTING_ID"); entity.HasOne(d => d.Tenant) .WithMany(p => p.Settings) .HasForeignKey(d => d.TenantId) .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("REL_SETTING_TENANT_ID"); }); modelBuilder.Entity(entity => { entity.ToTable("Tenant", "base"); entity.HasIndex(e => e.Code, "IDX_TENANT_CODE") .IsUnique(); entity.HasKey(e => e.Id); entity.Property(e => e.Id).HasComment("Tenant primary key"); entity.Property(e => e.Code) .HasMaxLength(20) .HasComment("Tenant code. Main key to search."); entity.Property(e => e.Created) .HasColumnType("datetime") .HasDefaultValueSql("(getdate())") .HasComment("Record created timestamp"); entity.Property(e => e.IsLocked).HasComment("Flag if tenant locked (not accessable)"); entity.Property(e => e.LastAccess) .HasColumnType("datetime") .HasComment("Last access (usage) timestamp."); entity.Property(e => e.Modified) .HasColumnType("datetime") .HasComment("Record modified timestamp"); entity.Property(e => e.Modifier) .HasMaxLength(100) .HasComment("Record modifier signature"); entity.Property(e => e.Name) .HasMaxLength(200) .HasComment("Tenant name. Informational value."); }); modelBuilder.Entity(entity => { entity.HasNoKey(); entity.ToTable("TenantUser", "base"); entity.Property(e => e.TenantId).HasComment("Reference to tenant"); entity.Property(e => e.UserId).HasComment("Reference to user"); 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"); }); modelBuilder.Entity(entity => { entity.ToTable("User", "base"); entity.HasIndex(e => e.LoginName, "IDX_USER_LOGINNAME") .IsUnique(); entity.Property(e => e.Id).HasComment("User primary key"); entity.Property(e => e.Created) .HasColumnType("datetime") .HasDefaultValueSql("(getdate())") .HasComment("Record created timestamp"); entity.Property(e => e.IsLocked).HasComment("Flag if user access locked (not accessable)"); entity.Property(e => e.LoginName) .HasMaxLength(200) .HasComment("User login name name. Key search value"); entity.Property(e => e.Modified) .HasColumnType("datetime") .HasComment("Record modified timestamp"); entity.Property(e => e.Modifier) .HasMaxLength(100) .HasComment("Record modifier signature"); }); OnModelCreatingPartial(modelBuilder); } partial void OnModelCreatingPartial(ModelBuilder modelBuilder); } }