2023-04-01 14:32:31 +04:00
|
|
|
|
using HardwareShopDatabaseImplement.Models;
|
2023-04-01 16:42:28 +04:00
|
|
|
|
using HardwareShopDatabaseImplement.Models.ManyToMany;
|
|
|
|
|
using HardwareShopDatabaseImplement.Models.Storekeeper;
|
|
|
|
|
using HardwareShopDatabaseImplement.Models.Worker;
|
2023-04-01 14:32:31 +04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2023-05-19 22:47:00 +04:00
|
|
|
|
using Microsoft.Extensions.Options;
|
2023-04-01 14:32:31 +04:00
|
|
|
|
|
|
|
|
|
namespace HardwareShopDatabaseImplement
|
|
|
|
|
{
|
|
|
|
|
public class HardwareShopDatabase : DbContext
|
|
|
|
|
{
|
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
|
|
|
{
|
2023-05-19 22:54:53 +04:00
|
|
|
|
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=Computer_Hardware_Store1;Username=user;Password=12345");
|
2023-05-19 17:41:42 +04:00
|
|
|
|
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
2023-04-01 14:32:31 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
2023-04-02 16:22:58 +04:00
|
|
|
|
modelBuilder.Entity<ComponentBuild>().HasKey(x => new { x.ComponentId, x.BuildId });
|
2023-04-01 16:34:06 +04:00
|
|
|
|
modelBuilder.Entity<PurchaseBuild>().HasKey(x => new { x.PurchaseId, x.BuildId });
|
|
|
|
|
modelBuilder.Entity<PurchaseGood>().HasKey(x => new { x.PurchaseId, x.GoodId });
|
2023-04-01 17:48:07 +04:00
|
|
|
|
modelBuilder.Entity<GoodComponent>().HasKey(x => new { x.GoodId, x.ComponentId });
|
2023-04-01 20:03:03 +04:00
|
|
|
|
|
2023-04-08 16:56:53 +04:00
|
|
|
|
modelBuilder.Entity<User>(entity =>
|
|
|
|
|
{
|
2023-04-01 20:03:03 +04:00
|
|
|
|
entity.HasIndex(e => e.Login).IsUnique();
|
|
|
|
|
entity.HasIndex(e => e.Email).IsUnique();
|
|
|
|
|
});
|
2023-04-01 14:32:31 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual DbSet<Build> Builds { set; get; }
|
|
|
|
|
|
2023-04-02 16:22:58 +04:00
|
|
|
|
public virtual DbSet<ComponentBuild> ComponentsBuilds { set; get; }
|
2023-04-01 14:53:34 +04:00
|
|
|
|
|
2023-04-01 14:32:31 +04:00
|
|
|
|
public virtual DbSet<Comment> Comments { set; get; }
|
|
|
|
|
|
|
|
|
|
public virtual DbSet<Component> Components { set; get; }
|
|
|
|
|
|
|
|
|
|
public virtual DbSet<Good> Goods { set; get; }
|
|
|
|
|
|
2023-04-02 16:22:58 +04:00
|
|
|
|
public virtual DbSet<GoodComponent> GoodsComponents { set; get; }
|
2023-04-01 17:42:33 +04:00
|
|
|
|
|
2023-04-01 14:32:31 +04:00
|
|
|
|
public virtual DbSet<Order> Orders { set; get; }
|
|
|
|
|
|
2023-04-01 16:27:37 +04:00
|
|
|
|
public virtual DbSet<Purchase> Purchases { set; get; }
|
2023-04-01 14:32:31 +04:00
|
|
|
|
|
|
|
|
|
public virtual DbSet<PurchaseBuild> PurchasesBuilds { set; get; }
|
|
|
|
|
|
|
|
|
|
public virtual DbSet<PurchaseGood> PurchasesGoods { set; get; }
|
|
|
|
|
|
|
|
|
|
public virtual DbSet<User> Users { set; get; }
|
|
|
|
|
}
|
|
|
|
|
}
|