AppDbContext.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Application.ATG_Classic_App.Model;
  2. using Edge.Core.Database.Models;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace Application.ATG_Classic_App
  5. {
  6. public class AppDbContext : DbContext
  7. {
  8. private DbContextOptions options;
  9. public AppDbContext() : base()
  10. {
  11. }
  12. public AppDbContext(DbContextOptions options) : base(options) { this.options = options; }
  13. protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
  14. {
  15. //if (options == null)
  16. // optionsBuilder.UseSqlite("Data Source=Application.ATG_Classic_App_database.db");
  17. }
  18. protected override void OnModelCreating(ModelBuilder modelBuilder)
  19. {
  20. modelBuilder.Entity<TankProfileData>().HasIndex(p => new { p.BatchLabel, p.Height }).IsUnique(true);
  21. modelBuilder.Entity<Alarm>().HasIndex(a => new { a.TankNumber, a.Type, a.Priority, a.CreatedTimeStamp }).IsUnique(true);
  22. modelBuilder.Entity<Alarm>().HasIndex(a => new { a.TankNumber, a.Type, a.Priority, a.ClearedTimeStamp }).IsUnique(true);
  23. modelBuilder.Entity<Alarm>().HasIndex(a => new { a.CreatedTimeStamp }).IsUnique(false);
  24. modelBuilder.Entity<Alarm>().HasIndex(a => new { a.TankNumber }).IsUnique(false);
  25. modelBuilder.Entity<Delivery>().HasIndex(d => new { d.TankNumber, d.StartingDateTime }).IsUnique(true);
  26. modelBuilder.Entity<Inventory>().HasIndex(d => new { d.TankNumber, d.TimeStamp }).IsUnique(true);
  27. }
  28. public DbSet<TankOverallConfig> TankOverallConfigs { get; set; }
  29. public DbSet<TankLimitConfig> TankLimitConfigs { get; set; }
  30. public DbSet<ProductConfig> ProductConfigs { get; set; }
  31. public DbSet<ProbeConfig> ProbeConfigs { get; set; }
  32. public DbSet<TankConfig> TankConfigs { get; set; }
  33. public DbSet<TankProfileData> TankProfileDatas { get; set; }
  34. public DbSet<Alarm> Alarms { get; set; }
  35. public DbSet<Delivery> Deliveries { get; set; }
  36. public DbSet<Inventory> Inventories { get; set; }
  37. }
  38. }