using data.DAO; using Microsoft.EntityFrameworkCore; namespace data.Context { public class ApplicationDbContext : DbContext { public DbSet Students { get; set; } public DbSet Groups { get; set; } public DbSet Subjects { get; set; } public DbSet Semesters { get; set; } public DbSet Lessons { get; set; } public DbSet Attendances { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity() .HasOne(s => s.Group) .WithMany(g => g.Students) .HasForeignKey(s => s.GroupId); modelBuilder.Entity() .HasOne(l => l.Subject) .WithMany(s => s.Lessons) .HasForeignKey(l => l.SubjectId); modelBuilder.Entity() .HasOne(l => l.Semester) .WithMany(s => s.Lessons) .HasForeignKey(l => l.SemesterId); modelBuilder.Entity() .HasOne(l => l.Group) .WithMany(g => g.Lessons) .HasForeignKey(l => l.GroupId); modelBuilder.Entity() .HasOne(a => a.Student) .WithMany(s => s.Attendances) .HasForeignKey(a => a.StudentId); modelBuilder.Entity() .HasOne(a => a.Lesson) .WithMany(l => l.Attendances) .HasForeignKey(a => a.LessonId); } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseNpgsql("Host=45.67.56.214;Database=user17;Username=user17;Password=3JSONQyy;Port=5454"); } } }