using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Data; using System.Linq; namespace Data.SeaHavenIndustries { public class ApplicationDbContext : IdentityDbContext { public ApplicationDbContext(DbContextOptions options) : base(options) { } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); foreach (var foreignKey in builder.Model.GetEntityTypes().SelectMany (e => e.GetForeignKeys())) { foreignKey.DeleteBehavior = DeleteBehavior.Restrict; } builder.Entity() .HasIndex(t => t.Token) .IsUnique(); builder.Entity() .HasIndex(u => new { u.DispatchId, u.Status }) .IsUnique() .HasFilter("[Status] = 'Pending'"); builder.Entity() .HasIndex(l => new { l.WorkOrderId, l.FieldName }) .IsUnique(); builder.Entity() .Property(w => w.RowVersion) .IsRowVersion(); builder.Entity() .HasIndex(w => w.SiteCode) .HasFilter("[istemplate] = 0"); builder.Entity() .HasIndex(w => w.InternalWONumber) .HasFilter("[istemplate] = 0"); builder.Entity() .HasIndex(w => new { w.LifecycleStatus, w.ScheduledDate }) .HasFilter("[istemplate] = 0"); builder.Entity() .Property(d => d.RowVersion) .IsRowVersion(); builder.Entity() .HasOne(w => w.PrimaryDispatch) .WithMany() .HasForeignKey(w => w.PrimaryDispatchId) .OnDelete(DeleteBehavior.Restrict); } public DbSet Categories { get; set; } public DbSet Locations { get; set; } public DbSet Contacts { get; set; } public DbSet workOrders { get; set; } public DbSet