ComplianceServer/code/Hg.Core.EntityFramework/DncmsbaseDbContext.cs

105 lines
4.0 KiB
C#

using Hg.Core.Entity.HgCrm;
using Hg.Core.Entity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Diagnostics;
namespace Hg.Core.EntityFramework
{
public class DncmsbaseDbContext : DbContext
{
public DncmsbaseDbContext(DbContextOptions<DncmsbaseDbContext> options) : base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == "Development")
{
var loggerFactory = new LoggerFactory();
loggerFactory.AddProvider(new EFLoggerProvider());
optionsBuilder.UseLoggerFactory(loggerFactory);
}
optionsBuilder.ConfigureWarnings(b => b.Ignore(CoreEventId.ContextInitialized));
base.OnConfiguring(optionsBuilder);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Deptment>()
.HasOne(x => x.DeptmentGroup)
.WithMany(x => x.Deptments)
.HasForeignKey(x => x.Groupid);
modelBuilder.Entity<LiveAuditLogPlayBack>()
.HasOne(x => x.ZhiboSystemSchedulesPlayback)
.WithMany(x => x.LiveAuditLogPlayBack)
.HasForeignKey(x => x.playBackId);
modelBuilder.Entity<LiveAuditLogPlayBack>()
.HasOne(x => x.CMS_LiveAuditLog)
.WithMany(x => x.LiveAuditLogPlayBack)
.HasForeignKey(x => x.logId);
modelBuilder.Entity<ZhiboSystemSchedulesToRoom>()
.HasNoKey();
modelBuilder.Entity<ComplianceCheckStatus>()
.HasOne(x => x.Lecturer)
.WithMany(x => x.ComplianceCheckStatus)
.HasForeignKey(x => x.SourceId);
modelBuilder.Entity<ComplianceCheckStatus>()
.HasOne(x => x.News)
.WithMany(x => x.ComplianceCheckStatus)
.HasForeignKey(x => x.SourceId);
modelBuilder.Entity<ComplianceCheckStatus>()
.HasOne(x => x.ZhiboSystemPlan)
.WithMany(x => x.ComplianceCheckStatus)
.HasForeignKey(x => x.SourceId);
base.OnModelCreating(modelBuilder);
}
public DbSet<DeptmentGroup> DeptmentGroup { get; set; }
public DbSet<Deptment> Deptment { get; set; }
public DbSet<Risktips> Risktips { get; set; }
public DbSet<ZhiboSystemRoom> ZhiboSystemRoom { get; set; }
public DbSet<ZhiboSystemSchedules> ZhiboSystemSchedules { get; set; }
public DbSet<Tiktok> Tiktok { get; set; }
public DbSet<WeiXinChannels> WeiXinChannels { get; set; }
public DbSet<KuaiShou> KuaiShou { get; set; }
public DbSet<Lecturer> Lecturer { get; set; }
public DbSet<ZhiboSystemSchedulesToRoom> ZhiboSystemSchedulesToRoom { get; set; }
public DbSet<LivePlatform> LivePlatform { get; set; }
public DbSet<CMS_LiveAuditLog> LiveAuditLog { get; set; }
public DbSet<LiveAuditLogPlayBack> LiveAuditLogPlayBack { get; set; }
public DbSet<ZhiboSystemSchedulesPlayback> ZhiboSystemSchedulesPlayback { get; set; }
public DbSet<ZhiboSystemPlan> ZhiboSystemPlan { get; set; }
public DbSet<ZhiboSystemPlanLog> ZhiboSystemPlanLog { get; set; }
public DbSet<ZhibosySytemPlanCheckStatusLog> ZhibosySytemPlanCheckStatusLog { get; set; }
public DbSet<ZhiboSystemPlanStatusLog> ZhiboSystemPlanStatusLog { get; set; }
public DbSet<ComplianceCheckStatus> ComplianceCheckStatus { get; set; }
public DbSet<News> News { get; set; }
public DbSet<NewsClass> NewsClass { get; set; }
public DbSet<NewsContent> NewsContent { get; set; }
public DbSet<Authors> Authors { get; set; }
public DbSet<NewsSubType> NewsSubType { get; set; }
}
}