using DG.EntityFramework; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.Logging; namespace Zxd.EntityFramework { public class DncmsDbContext : DbContext { public DncmsDbContext(DbContextOptions 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().HasNoKey(); modelBuilder.Entity().HasKey(c => new { c.Appid, c.Userid, c.Externaluserid }); modelBuilder.Entity() .HasOne(x => x.ResourceFlowConfig) .WithMany(x => x.ResourceFlowConfigFrom) .HasForeignKey(x => x.ConfigId); modelBuilder.Entity() .HasOne(x => x.ResourceFlowConfig) .WithMany(x => x.ResourceFlowConfigTo) .HasForeignKey(x => x.ConfigId); modelBuilder.Entity() .HasOne(x => x.ResourceFlowConfig) .WithMany(x => x.ResourceFlowLog) .HasForeignKey(x => x.ConfigId); base.OnModelCreating(modelBuilder); } public DbSet WeworkExternalUserTotal { get; set; } public DbSet WeworkExternalUser { get; set; } public DbSet ResourceFlowConfig { get; set; } public DbSet ResourceFlowConfigFrom { get; set; } public DbSet ResourceFlowConfigTo { get; set; } public DbSet ResourceFlowDimission { get; set; } } }