Demo/Data/RemoteData/RemoteDataBase/RemoteDatabaseContext.cs

30 lines
1.2 KiB
C#
Raw Normal View History

2024-10-24 20:41:31 +00:00
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Microsoft.EntityFrameworkCore;
2024-10-28 03:24:11 +00:00
namespace Demo.Data.RemoteData.RemoteDataBase
2024-10-24 20:41:31 +00:00
{
2024-10-28 03:24:11 +00:00
public class RemoteDatabaseContext: DbContext
{
public DbSet<GroupDAO> Groups {get; set; }
public DbSet<UserDAO> Users {get; set;}
public DbSet<PresenceDAO> PresenceDaos{get; set; }
2024-10-24 20:41:31 +00:00
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
2024-10-28 03:24:11 +00:00
optionsBuilder.UseNpgsql("Host=localhost;Port=5433;Username=myuser;Password=mypassword;Database=mydatabase");
2024-10-24 20:41:31 +00:00
}
2024-10-28 03:24:11 +00:00
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 {
2024-10-24 20:41:31 +00:00
presence.UserGuid,
presence.Date,
presence.LessonNumber
});
}
}
}