72 lines
2.1 KiB
C#

using DigitalData.UserManager.Domain.Entities;
using DigitalData.UserManager.Infrastructure;
using DigitalData.UserManager.Infrastructure.Contracts;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.SqlServer.Query.Internal;
using WorkFlow.Domain.Entities;
namespace WorkFlow.Infrastructure;
public class WFDBContext : DbContext, IUserManagerDbContext
{
public DbSet<Config> Configs { get; set; }
public DbSet<PControlsTF> ProfileControlsTFs { get; set; }
public DbSet<Profile> Profiles { get; set; }
public DbSet<PObject> Objects { get; set; }
public DbSet<PObjectState> ProfileObjStates { get; set; }
public DbSet<State> States { get; set; }
public DbSet<GroupOfUser> GroupOfUsers { get; set; }
public DbSet<Group> Groups { get; set; }
public DbSet<ModuleOfUser> ModuleOfUsers { get; set; }
public DbSet<Module> Modules { get; set; }
public DbSet<User> Users { get; set; }
public DbSet<UserRep> UserReps { get; set; }
public DbSet<ClientUser> ClientUsers { get; set; }
public DbSet<Button> Buttons { get; set; }
public WFDBContext(DbContextOptions options) : base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ConfigureUserManager();
modelBuilder.Entity<PObjectState>()
.HasMany(objState => objState.TFControls)
.WithOne()
.HasForeignKey(control => control.ObjStateId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<PObjectState>()
.HasMany(objState => objState.TfFiles)
.WithOne()
.HasForeignKey(file => file.ObjStateId);
modelBuilder.Entity<PObject>()
.HasMany(p => p.StateHistories)
.WithOne()
.HasForeignKey(hist => hist.ObjectId);
modelBuilder.Entity<PObject>()
.HasMany(obj => obj.ControlsUpdates)
.WithOne()
.HasForeignKey(cu => cu.ObjId)
.OnDelete(DeleteBehavior.Cascade);
base.OnModelCreating(modelBuilder);
}
}