presence/data/RemoteData/RemoteDataBase/RemoteDataBaseContext.cs

34 lines
1.2 KiB
C#
Raw Normal View History

2024-11-01 14:11:27 +00:00
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Microsoft.EntityFrameworkCore;
namespace Demo.Data.RemoteData.RemoteDataBase
{
public class RemoteDatabaseContext: DbContext
{
public DbSet<GroupDAO> Groups {get; set; }
public DbSet<UserDAO> Users {get; set;}
public DbSet<PresenceDAO> PresenceDaos{get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql("Host=localhost;" +
"Port=5432;" +
"Username=postgres;" +
"Password=1234;" +
"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<PresenceDAO>().HasKey(presence => new {
presence.UserGuid,
presence.Date,
presence.LessonNumber
});
}
}
}