2021-03-26 20:09:52 +04:00
|
|
|
|
using DatabaseCore.Models.Security;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
namespace DatabaseCore
|
|
|
|
|
{
|
|
|
|
|
public class DatabaseContext : DbContext
|
|
|
|
|
{
|
|
|
|
|
public DatabaseContext() : base() { }
|
|
|
|
|
|
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
|
|
|
{
|
|
|
|
|
if (optionsBuilder.IsConfigured == false)
|
|
|
|
|
{
|
|
|
|
|
#if RELEASE
|
2021-03-28 19:15:55 +04:00
|
|
|
|
var connectionString = ModuleTools.ServiceProvider.ServiceProviderLoader.GetConfigData("connectionString");
|
2021-03-26 20:09:52 +04:00
|
|
|
|
optionsBuilder.UseSqlServer(connectionString);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
optionsBuilder.UseSqlServer(@"Data Source=CHESHIR\SQLEXPRESS;Initial Catalog=DepartmentDatabasePortal;persist security info=True;user id=admin;password=cheshirSA123;MultipleActiveResultSets=True;");
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
base.OnConfiguring(optionsBuilder);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-01 21:30:29 +04:00
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
|
|
|
|
modelBuilder.Entity<EnviromentSetting>().HasIndex(s => s.Key).IsUnique();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-26 20:09:52 +04:00
|
|
|
|
|
|
|
|
|
public virtual DbSet<Access> Accesses { set; get; }
|
|
|
|
|
public virtual DbSet<EnviromentSetting> EnviromentSettings { set; get; }
|
|
|
|
|
public virtual DbSet<Role> Roles { set; get; }
|
|
|
|
|
public virtual DbSet<User> Users { set; get; }
|
|
|
|
|
public virtual DbSet<UserRole> UserRoles { set; get; }
|
|
|
|
|
}
|
|
|
|
|
}
|