2023-03-28 21:24:52 +04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2023-03-30 14:06:44 +04:00
|
|
|
|
using System.Configuration;
|
2023-03-28 21:24:52 +04:00
|
|
|
|
|
|
|
|
|
namespace BeautySaloonDatabaseImplement;
|
|
|
|
|
|
|
|
|
|
public partial class NewdbContext : DbContext
|
|
|
|
|
{
|
|
|
|
|
public NewdbContext()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NewdbContext(DbContextOptions<NewdbContext> options)
|
|
|
|
|
: base(options)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual DbSet<Client> Clients { get; set; }
|
|
|
|
|
|
|
|
|
|
public virtual DbSet<Employee> Employees { get; set; }
|
|
|
|
|
|
|
|
|
|
public virtual DbSet<Order> Orders { get; set; }
|
|
|
|
|
|
|
|
|
|
public virtual DbSet<Position> Positions { get; set; }
|
|
|
|
|
|
|
|
|
|
public virtual DbSet<Service> Services { get; set; }
|
|
|
|
|
|
|
|
|
|
public virtual DbSet<ServiceOrder> ServiceOrders { get; set; }
|
|
|
|
|
|
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
2023-03-30 14:06:44 +04:00
|
|
|
|
{
|
|
|
|
|
string connectString = ConfigurationManager.AppSettings["connect"]!;
|
|
|
|
|
optionsBuilder.UseNpgsql(connectString);
|
|
|
|
|
}
|
2023-03-28 21:24:52 +04:00
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
|
|
|
|
modelBuilder.Entity<Client>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasKey(e => e.Id).HasName("client_pkey");
|
|
|
|
|
|
|
|
|
|
entity.ToTable("clients", tb => tb.HasComment("Сущность клиенты"));
|
|
|
|
|
|
|
|
|
|
entity.Property(e => e.Id)
|
|
|
|
|
.ValueGeneratedNever()
|
|
|
|
|
.HasComment("Уникальный идентификатор")
|
|
|
|
|
.HasColumnName("id");
|
|
|
|
|
entity.Property(e => e.Name)
|
|
|
|
|
.HasMaxLength(40)
|
|
|
|
|
.HasComment("Имя")
|
|
|
|
|
.HasColumnName("name");
|
|
|
|
|
entity.Property(e => e.Patronymic)
|
|
|
|
|
.HasMaxLength(40)
|
|
|
|
|
.HasDefaultValueSql("'Отсутствует'::character varying")
|
|
|
|
|
.HasComment("Отчество")
|
|
|
|
|
.HasColumnName("patronymic");
|
|
|
|
|
entity.Property(e => e.Phone)
|
|
|
|
|
.HasMaxLength(11)
|
|
|
|
|
.HasComment("Номер телефона")
|
|
|
|
|
.HasColumnName("phone");
|
|
|
|
|
entity.Property(e => e.Surname)
|
|
|
|
|
.HasMaxLength(40)
|
|
|
|
|
.HasComment("Фамилия")
|
|
|
|
|
.HasColumnName("surname");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<Employee>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasKey(e => e.Id).HasName("employee_pkey");
|
|
|
|
|
|
|
|
|
|
entity.ToTable("employees", tb => tb.HasComment("Сущность сотрудники"));
|
|
|
|
|
|
|
|
|
|
entity.Property(e => e.Id)
|
|
|
|
|
.ValueGeneratedNever()
|
|
|
|
|
.HasComment("Уникальный идентификатор")
|
|
|
|
|
.HasColumnName("id");
|
|
|
|
|
entity.Property(e => e.Name)
|
|
|
|
|
.HasMaxLength(40)
|
|
|
|
|
.HasComment("Имя")
|
|
|
|
|
.HasColumnName("name");
|
|
|
|
|
entity.Property(e => e.Patronymic)
|
|
|
|
|
.HasMaxLength(40)
|
|
|
|
|
.HasDefaultValueSql("'Отсутствует'::character varying")
|
|
|
|
|
.HasComment("Отчество")
|
|
|
|
|
.HasColumnName("patronymic");
|
|
|
|
|
entity.Property(e => e.Phone)
|
|
|
|
|
.HasMaxLength(11)
|
|
|
|
|
.HasComment("Номер телефона")
|
|
|
|
|
.HasColumnName("phone");
|
|
|
|
|
entity.Property(e => e.PositionId)
|
|
|
|
|
.HasComment("Идентификатор позиции")
|
|
|
|
|
.HasColumnName("position_id");
|
|
|
|
|
entity.Property(e => e.Surname)
|
|
|
|
|
.HasMaxLength(40)
|
|
|
|
|
.HasComment("Фамилия")
|
|
|
|
|
.HasColumnName("surname");
|
|
|
|
|
|
|
|
|
|
entity.HasOne(d => d.Position).WithMany(p => p.Employees)
|
|
|
|
|
.HasForeignKey(d => d.PositionId)
|
|
|
|
|
.OnDelete(DeleteBehavior.ClientSetNull)
|
|
|
|
|
.HasConstraintName("position_fk");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<Order>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasKey(e => e.Id).HasName("order_table_pkey");
|
|
|
|
|
|
|
|
|
|
entity.ToTable("orders", tb => tb.HasComment("Сущность заказы"));
|
|
|
|
|
|
|
|
|
|
entity.Property(e => e.Id)
|
|
|
|
|
.ValueGeneratedNever()
|
|
|
|
|
.HasComment("Уникальный идентификатор")
|
|
|
|
|
.HasColumnName("id");
|
|
|
|
|
entity.Property(e => e.ClientId)
|
|
|
|
|
.HasComment("Идентификатор клиента")
|
|
|
|
|
.HasColumnName("client_id");
|
|
|
|
|
entity.Property(e => e.Date)
|
|
|
|
|
.HasComment("Дата")
|
|
|
|
|
.HasColumnName("date");
|
|
|
|
|
entity.Property(e => e.EmployeeId)
|
|
|
|
|
.HasComment("Идентификатор сотрудника")
|
|
|
|
|
.HasColumnName("employee_id");
|
|
|
|
|
entity.Property(e => e.Sum)
|
|
|
|
|
.HasPrecision(6, 2)
|
|
|
|
|
.HasComment("Сумма")
|
|
|
|
|
.HasColumnName("sum");
|
|
|
|
|
|
|
|
|
|
entity.HasOne(d => d.Client).WithMany(p => p.Orders)
|
|
|
|
|
.HasForeignKey(d => d.ClientId)
|
|
|
|
|
.OnDelete(DeleteBehavior.ClientSetNull)
|
|
|
|
|
.HasConstraintName("client_fk");
|
|
|
|
|
|
|
|
|
|
entity.HasOne(d => d.Employee).WithMany(p => p.Orders)
|
|
|
|
|
.HasForeignKey(d => d.EmployeeId)
|
|
|
|
|
.OnDelete(DeleteBehavior.ClientSetNull)
|
|
|
|
|
.HasConstraintName("employee_fk");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<Position>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasKey(e => e.Id).HasName("position_pkey");
|
|
|
|
|
|
|
|
|
|
entity.ToTable("positions", tb => tb.HasComment("Сущность позиции"));
|
|
|
|
|
|
|
|
|
|
entity.Property(e => e.Id)
|
|
|
|
|
.ValueGeneratedNever()
|
|
|
|
|
.HasComment("Идентификатор")
|
|
|
|
|
.HasColumnName("id");
|
|
|
|
|
entity.Property(e => e.Name)
|
|
|
|
|
.HasMaxLength(40)
|
|
|
|
|
.HasComment("Название")
|
|
|
|
|
.HasColumnName("name");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<Service>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasKey(e => e.Id).HasName("service_pkey");
|
|
|
|
|
|
|
|
|
|
entity.ToTable("services", tb => tb.HasComment("Сущность услуги"));
|
|
|
|
|
|
|
|
|
|
entity.Property(e => e.Id)
|
|
|
|
|
.ValueGeneratedNever()
|
|
|
|
|
.HasComment("Уникальный идентификатор")
|
|
|
|
|
.HasColumnName("id");
|
|
|
|
|
entity.Property(e => e.Name)
|
2023-03-30 02:29:40 +04:00
|
|
|
|
.HasMaxLength(100)
|
2023-03-28 21:24:52 +04:00
|
|
|
|
.HasComment("Название")
|
|
|
|
|
.HasColumnName("name");
|
|
|
|
|
entity.Property(e => e.Price)
|
|
|
|
|
.HasPrecision(6, 2)
|
|
|
|
|
.HasComment("Цена")
|
|
|
|
|
.HasColumnName("price");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<ServiceOrder>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.HasKey(e => new { e.ServiceId, e.OrderId }).HasName("service_order_pkey");
|
|
|
|
|
|
|
|
|
|
entity.ToTable("service_order", tb => tb.HasComment("Сущность-связь услуги с заказом"));
|
|
|
|
|
|
|
|
|
|
entity.Property(e => e.ServiceId)
|
|
|
|
|
.HasComment("Составной первичный ключ: идентификатор услуги")
|
|
|
|
|
.HasColumnName("service_id");
|
|
|
|
|
entity.Property(e => e.OrderId)
|
|
|
|
|
.HasComment("Составной первичный ключ: идентификатор заказа")
|
|
|
|
|
.HasColumnName("order_id");
|
|
|
|
|
entity.Property(e => e.Date)
|
|
|
|
|
.HasPrecision(6)
|
|
|
|
|
.HasComment("Время")
|
|
|
|
|
.HasColumnName("date");
|
|
|
|
|
entity.Property(e => e.EmployeeId)
|
|
|
|
|
.HasComment("Идентификатор сотрудника")
|
|
|
|
|
.HasColumnName("employee_id");
|
|
|
|
|
|
|
|
|
|
entity.HasOne(d => d.Employee).WithMany(p => p.ServiceOrders)
|
|
|
|
|
.HasForeignKey(d => d.EmployeeId)
|
2023-03-29 22:56:00 +04:00
|
|
|
|
.OnDelete(DeleteBehavior.Restrict)
|
|
|
|
|
.HasConstraintName("service_order_employee_id_fkey");
|
|
|
|
|
|
|
|
|
|
entity.HasOne(d => d.Order).WithMany(p => p.ServiceOrders)
|
|
|
|
|
.HasForeignKey(d => d.OrderId)
|
|
|
|
|
.OnDelete(DeleteBehavior.Restrict)
|
|
|
|
|
.HasConstraintName("service_order_order_id_fkey");
|
|
|
|
|
|
|
|
|
|
entity.HasOne(d => d.Service).WithMany(p => p.ServiceOrders)
|
|
|
|
|
.HasForeignKey(d => d.ServiceId)
|
|
|
|
|
.OnDelete(DeleteBehavior.Restrict)
|
|
|
|
|
.HasConstraintName("service_order_service_id_fkey");
|
2023-03-28 21:24:52 +04:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
OnModelCreatingPartial(modelBuilder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
2023-03-29 22:56:00 +04:00
|
|
|
|
}
|