BaseDbContext.cs 2.44 KB
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System.Data.SqlClient;
using Hh.Mes.Common;
using Hh.Mes.Common.config;


namespace WebRepository
{
    public sealed class BaseDBContext : DbContext
    {
        public BaseDBContext(DbContextOptions<BaseDBContext> options) : base(options)
        {
            var connectionStrings = ConfigRead.GetInstance.GetAppsetConnection();
            Database.GetDbConnection().ConnectionString = connectionStrings.BaseDBContext;
        }
        public DbSet<SysJob> SysJobs { get; set; }
        public DbSet<SysCount> SysCounts { get; set; }
        public DbSet<SysDept> SysDepts { get; set; }
        public DbSet<SysInfo> SysInfos { get; set; }

        public DbSet<SysModule> SysModules { get; set; }
        public DbSet<SysModuleElement> SysModuleElements { get; set; }
        public DbSet<SysRelevance> SysRelevances { get; set; }
        public DbSet<SysRole> SysRoles { get; set; }
        public DbSet<SysUser> SysUsers { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {

            modelBuilder.Entity<SysCount>().HasKey(c => c.Type);
            modelBuilder.Entity<SysCount>().Property(c => c.Type).HasColumnName("Type");

            modelBuilder.Entity<SysDept>().HasKey(c => c.Id);
            modelBuilder.Entity<SysDept>().Property(c => c.Id).HasColumnName("id");

            modelBuilder.Entity<SysInfo>().HasKey(c => c.Id);
            modelBuilder.Entity<SysInfo>().Property(c => c.Id).HasColumnName("id");


            modelBuilder.Entity<SysModule>().HasKey(c => c.Id);
            modelBuilder.Entity<SysModule>().Property(c => c.Id).HasColumnName("id");

            modelBuilder.Entity<SysModuleElement>().HasKey(c => c.Id);
            modelBuilder.Entity<SysModuleElement>().Property(c => c.Id).HasColumnName("id");


            modelBuilder.Entity<SysRelevance>().HasKey(c => c.Id);
            modelBuilder.Entity<SysRelevance>().Property(c => c.Id).HasColumnName("id");

            modelBuilder.Entity<SysRole>().HasKey(c => c.Id);
            modelBuilder.Entity<SysRole>().Property(c => c.Id).HasColumnName("id");

            modelBuilder.Entity<SysUser>().HasKey(c => c.Id);
            modelBuilder.Entity<SysUser>().Property(c => c.Id).HasColumnName("id");

            modelBuilder.Entity<SysJob>().HasKey(c => c.Id);
            modelBuilder.Entity<SysJob>().Property(c => c.Id).HasColumnName("id");

        }
    }
}