using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata.Internal; using PartSource.Data.Converters; using PartSource.Data.Models; namespace PartSource.Data.Contexts { public class PartSourceContext : DbContext { public PartSourceContext(DbContextOptions contextOptions) : base(contextOptions) { } public DbSet ApiClients { get; set; } public DbSet DcfMappings { get; set; } public DbSet ImportData { get; set; } public DbSet ImportMetrics { get; set; } public DbSet PartData { get; set; } public DbSet PartImages { get; set; } public DbSet PartPrices { get; set; } // public DbSet Parts { get; set; } public DbSet ShopifyChangelogs { get; set; } public DbSet Vehicles { get; set; } public DbSet PartAvailabilities { get; set; } public DbSet BaseVehicles { get; set; } public DbSet Engines { get; set; } public DbSet Submodels { get; set; } public DbSet VehicleMakes { get; set; } public DbSet VehicleModels { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity().HasKey(p => new { p.Store, p.SKU }); modelBuilder.Entity().HasKey(d => new { d.LineCode, d.WhiCode }); modelBuilder.Entity() .Property(s => s.ResourceType) .HasConversion(new TypeToStringConverter()); modelBuilder.Entity() .Property(s => s.Data) .HasConversion(new ObjectToJsonConverter()); foreach (IMutableEntityType entityType in modelBuilder.Model.GetEntityTypes()) { entityType.SetTableName(entityType.ClrType.Name); } } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) { optionsBuilder.UseSqlServer("Server=localhost;Database=ps-whi-stage;Trusted_Connection=True;"); } } } }