presence/data/RemoteData/RemoteDataBase/RemoteDatabaseContext.cs

30 lines
1.2 KiB
C#
Raw Normal View History

2024-11-01 19:07:13 +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=5433;Username=myuser;Password=mypassword;Database=mydatabase");
}
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
});
}
}
}