39 lines
1.5 KiB
C#
39 lines
1.5 KiB
C#
|
using Microsoft.EntityFrameworkCore;
|
|||
|
using System.Collections.Generic;
|
|||
|
using TransportCompanyDatabaseImplement.Models;
|
|||
|
|
|||
|
namespace TransportCompanyDatabaseImplement
|
|||
|
{
|
|||
|
public class TransportCompanyDatabase : DbContext
|
|||
|
{
|
|||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|||
|
{
|
|||
|
if (!optionsBuilder.IsConfigured)
|
|||
|
{
|
|||
|
optionsBuilder.UseSqlServer(@"Data Source=LAPTOP-M2G96S06\SQLEXPRESS;Initial Catalog=TransportCompanyDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
|||
|
}
|
|||
|
base.OnConfiguring(optionsBuilder);
|
|||
|
}
|
|||
|
public virtual DbSet<Cargo> Cargos { set; get; }
|
|||
|
public virtual DbSet<Driver> Drivers { set; get; }
|
|||
|
public virtual DbSet<Point> Points { set; get; }
|
|||
|
public virtual DbSet<Transport> Transports { set; get; }
|
|||
|
public virtual DbSet<Transportation> Transportations { set; get; }
|
|||
|
|
|||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|||
|
{
|
|||
|
modelBuilder.Entity<Transportation>()
|
|||
|
.HasOne(t => t.PointTo)
|
|||
|
.WithMany(p => p.TransportationsTo)
|
|||
|
.HasForeignKey(t => t.PointToId)
|
|||
|
.OnDelete(DeleteBehavior.Restrict);
|
|||
|
|
|||
|
modelBuilder.Entity<Transportation>()
|
|||
|
.HasOne(t => t.PointFrom)
|
|||
|
.WithMany(p => p.TransportationsFrom)
|
|||
|
.HasForeignKey(t => t.PointFromId)
|
|||
|
.OnDelete(DeleteBehavior.Restrict);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|