248 lines
10 KiB
C#
248 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace DataBase;
|
|
|
|
public partial class LogisticContext : DbContext
|
|
{
|
|
public LogisticContext()
|
|
{
|
|
}
|
|
|
|
public LogisticContext(DbContextOptions<LogisticContext> options)
|
|
: base(options)
|
|
{
|
|
}
|
|
|
|
public virtual DbSet<Car> Cars { get; set; }
|
|
|
|
public virtual DbSet<Company> Companies { get; set; }
|
|
|
|
public virtual DbSet<Human> Humans { get; set; }
|
|
|
|
public virtual DbSet<Place> Places { get; set; }
|
|
|
|
public virtual DbSet<Route> Routes { get; set; }
|
|
|
|
public virtual DbSet<Status> Statuses { get; set; }
|
|
|
|
public virtual DbSet<Voyage> Voyages { 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.101;Port=5432;Database=logistic;Username=postgres;Password=postgres");
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.Entity<Car>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id).HasName("car_pkey");
|
|
|
|
entity.ToTable("car", tb => tb.HasComment("Таблица машин"));
|
|
|
|
entity.Property(e => e.Id)
|
|
.HasDefaultValueSql("nextval('s3'::regclass)")
|
|
.HasComment("Айди машины")
|
|
.HasColumnName("id");
|
|
entity.Property(e => e.Model)
|
|
.HasMaxLength(100)
|
|
.HasDefaultValueSql("'car'::character varying")
|
|
.HasComment("Модель машины")
|
|
.HasColumnName("model");
|
|
entity.Property(e => e.StatusId)
|
|
.HasComment("Статус машины")
|
|
.HasColumnName("status_id");
|
|
entity.Property(e => e.Tonnage)
|
|
.HasComment("Грузоподъемность")
|
|
.HasColumnName("tonnage");
|
|
|
|
entity.HasOne(d => d.Status).WithMany(p => p.Cars)
|
|
.HasForeignKey(d => d.StatusId)
|
|
.OnDelete(DeleteBehavior.SetNull)
|
|
.HasConstraintName("car_status_id_fkey");
|
|
});
|
|
|
|
modelBuilder.Entity<Company>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id).HasName("company_pkey");
|
|
|
|
entity.ToTable("company", tb => tb.HasComment("Таблица компаний-заказчиков"));
|
|
|
|
entity.Property(e => e.Id)
|
|
.HasDefaultValueSql("nextval('s2'::regclass)")
|
|
.HasComment("Айди компании")
|
|
.HasColumnName("id");
|
|
entity.Property(e => e.StatusId)
|
|
.HasComment("Статус компании")
|
|
.HasColumnName("status_id");
|
|
entity.Property(e => e.Title)
|
|
.HasMaxLength(100)
|
|
.HasDefaultValueSql("'company'::character varying")
|
|
.HasComment("Наимнование компании")
|
|
.HasColumnName("title");
|
|
|
|
entity.HasOne(d => d.Status).WithMany(p => p.Companies)
|
|
.HasForeignKey(d => d.StatusId)
|
|
.OnDelete(DeleteBehavior.SetNull)
|
|
.HasConstraintName("company_status_id_fkey");
|
|
});
|
|
|
|
modelBuilder.Entity<Human>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id).HasName("human_pkey");
|
|
|
|
entity.ToTable("human", tb => tb.HasComment("Таблица водителей"));
|
|
|
|
entity.Property(e => e.Id)
|
|
.HasDefaultValueSql("nextval('s4'::regclass)")
|
|
.HasComment("Айди человека")
|
|
.HasColumnName("id");
|
|
entity.Property(e => e.Name)
|
|
.HasMaxLength(100)
|
|
.HasDefaultValueSql("'name'::character varying")
|
|
.HasComment("ФИО водителя")
|
|
.HasColumnName("name");
|
|
entity.Property(e => e.Phone)
|
|
.HasMaxLength(12)
|
|
.HasDefaultValueSql("'N'::character varying")
|
|
.HasComment("Телефон водителя")
|
|
.HasColumnName("phone");
|
|
entity.Property(e => e.StatusId)
|
|
.HasComment("Статус водителя")
|
|
.HasColumnName("status_id");
|
|
|
|
entity.HasOne(d => d.Status).WithMany(p => p.Humans)
|
|
.HasForeignKey(d => d.StatusId)
|
|
.OnDelete(DeleteBehavior.SetNull)
|
|
.HasConstraintName("human_status_id_fkey");
|
|
});
|
|
|
|
modelBuilder.Entity<Place>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id).HasName("place_pkey");
|
|
|
|
entity.ToTable("place", tb => tb.HasComment("Таблица мест"));
|
|
|
|
entity.Property(e => e.Id)
|
|
.HasDefaultValueSql("nextval('s5'::regclass)")
|
|
.HasComment("Айди места")
|
|
.HasColumnName("id");
|
|
entity.Property(e => e.Title)
|
|
.HasMaxLength(100)
|
|
.HasDefaultValueSql("'place'::character varying")
|
|
.HasComment("Наименование места")
|
|
.HasColumnName("title");
|
|
});
|
|
|
|
modelBuilder.Entity<Route>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id).HasName("route_pkey");
|
|
|
|
entity.ToTable("route", tb => tb.HasComment("Таблица маршрутов"));
|
|
|
|
entity.Property(e => e.Id)
|
|
.HasDefaultValueSql("nextval('s6'::regclass)")
|
|
.HasComment("Айди маршрутта")
|
|
.HasColumnName("id");
|
|
entity.Property(e => e.Length)
|
|
.HasComment("Протяженность маршрута")
|
|
.HasColumnName("length");
|
|
entity.Property(e => e.PlaceEnd)
|
|
.HasComment("Места отправки")
|
|
.HasColumnName("place_end");
|
|
entity.Property(e => e.PlaceStart)
|
|
.HasComment("Места прибытия")
|
|
.HasColumnName("place_start");
|
|
|
|
entity.HasOne(d => d.PlaceEndNavigation).WithMany(p => p.RoutePlaceEndNavigations)
|
|
.HasForeignKey(d => d.PlaceEnd)
|
|
.OnDelete(DeleteBehavior.Restrict)
|
|
.HasConstraintName("route_placeend_fkey");
|
|
|
|
entity.HasOne(d => d.PlaceStartNavigation).WithMany(p => p.RoutePlaceStartNavigations)
|
|
.HasForeignKey(d => d.PlaceStart)
|
|
.OnDelete(DeleteBehavior.Restrict)
|
|
.HasConstraintName("route_placestart_fkey");
|
|
});
|
|
|
|
modelBuilder.Entity<Status>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id).HasName("status_pkey");
|
|
|
|
entity.ToTable("status", tb => tb.HasComment("Таблица статусов"));
|
|
|
|
entity.Property(e => e.Id)
|
|
.HasDefaultValueSql("nextval('s1'::regclass)")
|
|
.HasComment("Айди статуса")
|
|
.HasColumnName("id");
|
|
entity.Property(e => e.Title)
|
|
.HasMaxLength(20)
|
|
.HasDefaultValueSql("'status'::character varying")
|
|
.HasComment("Название статуса")
|
|
.HasColumnName("title");
|
|
});
|
|
|
|
modelBuilder.Entity<Voyage>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id).HasName("voyage_pkey");
|
|
|
|
entity.ToTable("voyage", tb => tb.HasComment("Таблица рейсов"));
|
|
|
|
entity.Property(e => e.Id)
|
|
.HasDefaultValueSql("nextval('s7'::regclass)")
|
|
.HasComment("Айди рейса")
|
|
.HasColumnName("id");
|
|
entity.Property(e => e.CarId)
|
|
.HasComment("Машина для рейса")
|
|
.HasColumnName("car_id");
|
|
entity.Property(e => e.CompanyId)
|
|
.HasComment("Компания, заказавшая рейс")
|
|
.HasColumnName("company_id");
|
|
entity.Property(e => e.DateEnd)
|
|
.HasComment("Дедлайн")
|
|
.HasColumnName("date_end");
|
|
entity.Property(e => e.DateStart)
|
|
.HasComment("Дата отправки")
|
|
.HasColumnName("date_start");
|
|
entity.Property(e => e.HumanId)
|
|
.HasComment("Водитель для рейса")
|
|
.HasColumnName("human_id");
|
|
entity.Property(e => e.RouteId)
|
|
.HasComment("Маршрут рейса")
|
|
.HasColumnName("route_id");
|
|
|
|
entity.HasOne(d => d.Car).WithMany(p => p.Voyages)
|
|
.HasForeignKey(d => d.CarId)
|
|
.OnDelete(DeleteBehavior.Restrict)
|
|
.HasConstraintName("voyage_car_id_fkey");
|
|
|
|
entity.HasOne(d => d.Company).WithMany(p => p.Voyages)
|
|
.HasForeignKey(d => d.CompanyId)
|
|
.OnDelete(DeleteBehavior.Restrict)
|
|
.HasConstraintName("voyage_company_id_fkey");
|
|
|
|
entity.HasOne(d => d.Human).WithMany(p => p.Voyages)
|
|
.HasForeignKey(d => d.HumanId)
|
|
.OnDelete(DeleteBehavior.Restrict)
|
|
.HasConstraintName("voyage_human_id_fkey");
|
|
|
|
entity.HasOne(d => d.Route).WithMany(p => p.Voyages)
|
|
.HasForeignKey(d => d.RouteId)
|
|
.OnDelete(DeleteBehavior.Restrict)
|
|
.HasConstraintName("voyage_route_id_fkey");
|
|
});
|
|
modelBuilder.HasSequence("s1");
|
|
modelBuilder.HasSequence("s2");
|
|
modelBuilder.HasSequence("s3");
|
|
modelBuilder.HasSequence("s4");
|
|
modelBuilder.HasSequence("s5");
|
|
modelBuilder.HasSequence("s6");
|
|
modelBuilder.HasSequence("s7");
|
|
|
|
OnModelCreatingPartial(modelBuilder);
|
|
}
|
|
|
|
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
|
}
|