Raspisanie/Zurnal/RemaDateBase/RemoutDateBase.cs
2024-10-28 11:22:33 +03:00

34 lines
1.2 KiB
C#

using Microsoft.EntityFrameworkCore;
using Zurnal.RemaDateBase.DateDao;
public class RemoteDateBaseContext : DbContext
{
public RemoteDateBaseContext() { }
public DbSet<GroupDao> Group { get; set; }
public DbSet<UserDao> User { get; set; }
public DbSet<PresnceDao> Presence { get; set; }
public object Groups { get; internal set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Username=postgres;Password=123;Database=postgres");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<GroupDao>().HasKey(group => group.Id);
modelBuilder.Entity<GroupDao>().Property(group => group.Id).ValueGeneratedOnAdd();
modelBuilder.Entity<UserDao>().HasKey(user => user.Guid);
modelBuilder.Entity<UserDao>().Property(user => user.Guid).ValueGeneratedOnAdd();
modelBuilder.Entity<PresnceDao>().HasKey(presence => new
{
presence.UserGuid,
presence.Date,
presence.IsAttendensy,
presence.LessonNumber
});
}
}