pr1/presence/data/RemoteData/RemoteDataBase/RemoteDatabaseContext.cs

43 lines
1.6 KiB
C#
Raw Normal View History

2024-12-23 09:12:26 +00:00
using Microsoft.EntityFrameworkCore;
using presence.data.RemoteData.RemoteDataBase.DAO;
2024-12-05 09:30:01 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2024-12-23 09:12:26 +00:00
namespace presence.data.RemoteData.RemoteDataBase
2024-12-05 09:30:01 +00:00
{
public class RemoteDatabaseContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql("Host=45.67.56.214;" +
"Port=5421;" +
"Username=user7;" +
"Database=user7;" +
"Password=a8yLONBC");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
2024-12-19 17:36:57 +00:00
2024-12-05 09:30:01 +00:00
modelBuilder.Entity<GroupDao>().HasKey(group => group.Id);
modelBuilder.Entity<GroupDao>().Property(group => group.Id).ValueGeneratedOnAdd();
2024-12-19 17:36:57 +00:00
modelBuilder.Entity<UserDao>().HasKey(user => user.UserId);
modelBuilder.Entity<UserDao>().Property(user => user.UserId).ValueGeneratedOnAdd();
2024-12-05 09:30:01 +00:00
2024-12-19 17:36:57 +00:00
modelBuilder.Entity<PresenceDao>().HasKey(presence => presence.PresenceId);
modelBuilder.Entity<PresenceDao>().Property(presence => presence.PresenceId).ValueGeneratedOnAdd();
2024-12-05 09:30:01 +00:00
modelBuilder.Entity<PresenceDao>()
2024-12-19 17:36:57 +00:00
.HasOne(presence => presence.User)
.WithMany(user => user.Presences)
.HasForeignKey(presence => presence.UserId);
2024-12-05 09:30:01 +00:00
}
2024-12-19 17:36:57 +00:00
2024-12-05 09:30:01 +00:00
public DbSet<GroupDao> Groups { get; set; }
public DbSet<UserDao> Users { get; set; }
2024-12-19 17:36:57 +00:00
public DbSet<PresenceDao> Presences { get; set; }
2024-12-05 09:30:01 +00:00
}
}