Computer_Hardware_Store/HardwareShop/HardwareShopDatabaseImplement/HardwareShopDatabase.cs

53 lines
2.0 KiB
C#
Raw Permalink Normal View History

using HardwareShopDatabaseImplement.Models;
2023-04-01 16:42:28 +04:00
using HardwareShopDatabaseImplement.Models.ManyToMany;
using HardwareShopDatabaseImplement.Models.Storekeeper;
using HardwareShopDatabaseImplement.Models.Worker;
using Microsoft.EntityFrameworkCore;
namespace HardwareShopDatabaseImplement
{
public class HardwareShopDatabase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql("Host=localhost;Port=5433;Database=Computer_Hardware_Store1;Username=user;Password=12345");
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
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 });
modelBuilder.Entity<GoodComponent>().HasKey(x => new { x.GoodId, x.ComponentId });
modelBuilder.Entity<User>(entity =>
{
entity.HasIndex(e => e.Login).IsUnique();
entity.HasIndex(e => e.Email).IsUnique();
});
}
public virtual DbSet<Build> Builds { set; get; }
public virtual DbSet<ComponentBuild> ComponentsBuilds { set; get; }
public virtual DbSet<Comment> Comments { set; get; }
public virtual DbSet<Component> Components { set; get; }
public virtual DbSet<Good> Goods { set; get; }
public virtual DbSet<GoodComponent> GoodsComponents { set; get; }
2023-04-01 17:42:33 +04:00
public virtual DbSet<Order> Orders { set; get; }
public virtual DbSet<Purchase> Purchases { set; get; }
public virtual DbSet<PurchaseBuild> PurchasesBuilds { set; get; }
public virtual DbSet<PurchaseGood> PurchasesGoods { set; get; }
public virtual DbSet<User> Users { set; get; }
}
}