57 lines
1.8 KiB
C#
57 lines
1.8 KiB
C#
|
using data.DAO;
|
|||
|
using Microsoft.EntityFrameworkCore;
|
|||
|
|
|||
|
namespace data.Context
|
|||
|
{
|
|||
|
public class ApplicationDbContext : DbContext
|
|||
|
{
|
|||
|
public DbSet<Student> Students { get; set; }
|
|||
|
public DbSet<Group> Groups { get; set; }
|
|||
|
public DbSet<Subject> Subjects { get; set; }
|
|||
|
public DbSet<Semester> Semesters { get; set; }
|
|||
|
public DbSet<Lesson> Lessons { get; set; }
|
|||
|
public DbSet<Attendance> Attendances { get; set; }
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|||
|
{
|
|||
|
modelBuilder.Entity<Student>()
|
|||
|
.HasOne(s => s.Group)
|
|||
|
.WithMany(g => g.Students)
|
|||
|
.HasForeignKey(s => s.GroupId);
|
|||
|
|
|||
|
modelBuilder.Entity<Lesson>()
|
|||
|
.HasOne(l => l.Subject)
|
|||
|
.WithMany(s => s.Lessons)
|
|||
|
.HasForeignKey(l => l.SubjectId);
|
|||
|
|
|||
|
modelBuilder.Entity<Lesson>()
|
|||
|
.HasOne(l => l.Semester)
|
|||
|
.WithMany(s => s.Lessons)
|
|||
|
.HasForeignKey(l => l.SemesterId);
|
|||
|
|
|||
|
modelBuilder.Entity<Lesson>()
|
|||
|
.HasOne(l => l.Group)
|
|||
|
.WithMany(g => g.Lessons)
|
|||
|
.HasForeignKey(l => l.GroupId);
|
|||
|
|
|||
|
modelBuilder.Entity<Attendance>()
|
|||
|
.HasOne(a => a.Student)
|
|||
|
.WithMany(s => s.Attendances)
|
|||
|
.HasForeignKey(a => a.StudentId);
|
|||
|
|
|||
|
modelBuilder.Entity<Attendance>()
|
|||
|
.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");
|
|||
|
}
|
|||
|
}
|
|||
|
}
|