using Application.ATG_Classic_App.Model; using Edge.Core.Database.Models; using Microsoft.EntityFrameworkCore; namespace Application.ATG_Classic_App { public class AppDbContext : DbContext { private DbContextOptions options; public AppDbContext() : base() { } public AppDbContext(DbContextOptions options) : base(options) { this.options = options; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { //if (options == null) // optionsBuilder.UseSqlite("Data Source=Application.ATG_Classic_App_database.db"); } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<TankProfileData>().HasIndex(p => new { p.BatchLabel, p.Height }).IsUnique(true); modelBuilder.Entity<Alarm>().HasIndex(a => new { a.TankNumber, a.Type, a.Priority, a.CreatedTimeStamp }).IsUnique(true); modelBuilder.Entity<Alarm>().HasIndex(a => new { a.TankNumber, a.Type, a.Priority, a.ClearedTimeStamp }).IsUnique(true); modelBuilder.Entity<Alarm>().HasIndex(a => new { a.CreatedTimeStamp }).IsUnique(false); modelBuilder.Entity<Alarm>().HasIndex(a => new { a.TankNumber }).IsUnique(false); modelBuilder.Entity<Delivery>().HasIndex(d => new { d.TankNumber, d.StartingDateTime }).IsUnique(true); modelBuilder.Entity<Inventory>().HasIndex(d => new { d.TankNumber, d.TimeStamp }).IsUnique(true); } public DbSet<TankOverallConfig> TankOverallConfigs { get; set; } public DbSet<TankLimitConfig> TankLimitConfigs { get; set; } public DbSet<ProductConfig> ProductConfigs { get; set; } public DbSet<ProbeConfig> ProbeConfigs { get; set; } public DbSet<TankConfig> TankConfigs { get; set; } public DbSet<TankProfileData> TankProfileDatas { get; set; } public DbSet<Alarm> Alarms { get; set; } public DbSet<Delivery> Deliveries { get; set; } public DbSet<Inventory> Inventories { get; set; } } }