presence/data/DatabaseContext.cs

48 lines
1.7 KiB
C#
Raw Normal View History

2024-11-26 05:09:12 +00:00
using data.DAO;
using Microsoft.EntityFrameworkCore;
namespace data;
public class DatabaseContext : DbContext
{
public DatabaseContext() { }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseNpgsql("Host=45.67.56.214;Port=5454;Username=user13;Password=keNBA0yK");
public DbSet<Student> Students { get; set; }
public DbSet<Group> Groups { get; set; }
public DbSet<Diary> Diaries { get; set; }
public DbSet<Subject> Subjects { get; set; }
public DbSet<Traffic> Traffics { get; set; }
public DbSet<StudentGroupSubject> StudentGroupsSubjects { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Student>().Property(it => it.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<Group>().Property(it => it.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<Traffic>().Property(it => it.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<StudentGroupSubject>().Property(it => it.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<Diary>().Property(it => it.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<Subject>().Property(it => it.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<Student>()
.HasOne(it => it.Group);
modelBuilder.Entity<Diary>()
.HasOne(it => it.StudentGroupSubject);
modelBuilder.Entity<Diary>()
.HasOne(it => it.Traffic);
modelBuilder.Entity<Diary>()
.HasOne(it => it.Student);
modelBuilder.Entity<StudentGroupSubject>()
.HasOne(it => it.Group);
modelBuilder.Entity<StudentGroupSubject>()
.HasOne(it => it.Subject);
}
}