using Microsoft.EntityFrameworkCore; using UniversityDataBaseImplemet.Models; using Stream = UniversityDataBaseImplemet.Models.Stream; namespace UniversityDataBaseImplemet { public class Database : DbContext { protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (optionsBuilder.IsConfigured == false) { optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=UniversityCourseWork;Username=postgres;Password=0000"); } base.OnConfiguring(optionsBuilder); } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity() .HasKey(x => new { x.StudentId, x.DocumentId }); modelBuilder.Entity() .HasKey(x => new { x.EducationGroupId, x.DocumentId }); modelBuilder.Entity() .HasKey(x => new { x.EducationGroupId, x.StreamId }); modelBuilder.Entity() .HasKey(x => new { x.StudentId, x.StreamId }); modelBuilder.Entity() .HasOne(b => b.User) .WithMany(a => a.Documents) .OnDelete(DeleteBehavior.NoAction); modelBuilder.Entity() .HasOne(b => b.User) .WithMany(a => a.EducationStatuses) .OnDelete(DeleteBehavior.NoAction); modelBuilder.Entity() .HasOne(b => b.User) .WithMany(a => a.Students) .OnDelete(DeleteBehavior.NoAction); modelBuilder.Entity() .HasOne(b => b.User) .WithMany(a => a.Disciplines) .OnDelete(DeleteBehavior.NoAction); modelBuilder.Entity() .HasOne(b => b.User) .WithMany(a => a.EducationGroups) .OnDelete(DeleteBehavior.NoAction); modelBuilder.Entity() .HasOne(b => b.User) .WithMany(a => a.Streams) .OnDelete(DeleteBehavior.NoAction); } public virtual DbSet User { get; set; } public virtual DbSet Documents { get; set; } public virtual DbSet Discipline { get; set; } public virtual DbSet EducationStatuses { get; set; } public virtual DbSet EducationGroups { get; set; } public virtual DbSet EducationGroupsDocuments { get; set; } public virtual DbSet EducationGroupsStreams { get; set; } public virtual DbSet Streams { get; set; } public virtual DbSet Students { get; set; } public virtual DbSet StudentDocuments { get; set; } public virtual DbSet StudentStreams { get; set; } } }