using HardwareShopDatabaseImplement.Models; using HardwareShopDatabaseImplement.Models.ManyToMany; using HardwareShopDatabaseImplement.Models.Storekeeper; using HardwareShopDatabaseImplement.Models.Worker; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; namespace HardwareShopDatabaseImplement { public class HardwareShopDatabase : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=Computer_Hardware_Store1;Username=user;Password=12345"); AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity().HasKey(x => new { x.ComponentId, x.BuildId }); modelBuilder.Entity().HasKey(x => new { x.PurchaseId, x.BuildId }); modelBuilder.Entity().HasKey(x => new { x.PurchaseId, x.GoodId }); modelBuilder.Entity().HasKey(x => new { x.GoodId, x.ComponentId }); modelBuilder.Entity(entity => { entity.HasIndex(e => e.Login).IsUnique(); entity.HasIndex(e => e.Email).IsUnique(); }); } public virtual DbSet Builds { set; get; } public virtual DbSet ComponentsBuilds { set; get; } public virtual DbSet Comments { set; get; } public virtual DbSet Components { set; get; } public virtual DbSet Goods { set; get; } public virtual DbSet GoodsComponents { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Purchases { set; get; } public virtual DbSet PurchasesBuilds { set; get; } public virtual DbSet PurchasesGoods { set; get; } public virtual DbSet Users { set; get; } } }