SUBD_PIbd-21_Balberova_D.N./BeautySaloon/BeautySaloonDatabaseImplement/NewdbContext.cs
2023-03-30 13:59:00 +04:00

211 lines
8.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Microsoft.EntityFrameworkCore;
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)
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.
=> optionsBuilder.UseNpgsql("Host=192.168.56.102;Port=5432;Database=newdb;Username=username123;Password=12345");
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)
.HasMaxLength(100)
.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)
.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");
});
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}