2024-11-01 07:40:53 +00:00
|
|
|
|
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
namespace Demo.Data.RemoteData.RemoteDataBase
|
|
|
|
|
{
|
|
|
|
|
public class RemoteDatabaseContext : DbContext
|
|
|
|
|
{
|
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
|
|
|
{
|
|
|
|
|
optionsBuilder.UseNpgsql("Host=45.67.56.214;Port=5421;Username=user15;Database=user15;Password=3XkvwMOb");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
|
|
|
|
// Настройка ключа и автоматической генерации для GroupDao
|
|
|
|
|
modelBuilder.Entity<GroupDao>().HasKey(group => group.Id);
|
|
|
|
|
modelBuilder.Entity<GroupDao>().Property(group => group.Id).ValueGeneratedOnAdd();
|
|
|
|
|
|
|
|
|
|
// Настройка ключа и автоматической генерации для UserDao
|
|
|
|
|
modelBuilder.Entity<UserDao>().HasKey(user => user.Guid);
|
|
|
|
|
modelBuilder.Entity<UserDao>().Property(user => user.Guid).ValueGeneratedOnAdd();
|
|
|
|
|
|
|
|
|
|
// Настройка составного ключа для PresenceDao
|
|
|
|
|
modelBuilder.Entity<PresenceDao>().HasKey(presense => new
|
|
|
|
|
{
|
2024-11-05 18:36:49 +00:00
|
|
|
|
presense.Id
|
|
|
|
|
|
2024-11-01 07:40:53 +00:00
|
|
|
|
});
|
|
|
|
|
|
2024-11-06 09:07:50 +00:00
|
|
|
|
|
2024-11-01 07:40:53 +00:00
|
|
|
|
// Настройка связи UserDao с PresenceDao
|
|
|
|
|
modelBuilder.Entity<PresenceDao>()
|
2024-11-05 18:36:49 +00:00
|
|
|
|
.Property(presence => presence.Id)
|
|
|
|
|
.ValueGeneratedOnAdd();
|
2024-11-06 09:07:50 +00:00
|
|
|
|
modelBuilder.Entity<PresenceDao>().HasOne(presence => presence.UserDao).WithMany(user => user.Presences).HasForeignKey(presence => presence.UserGuid);
|
2024-11-05 18:36:49 +00:00
|
|
|
|
|
2024-11-01 07:40:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DbSet<GroupDao> Groups { get; set; }
|
|
|
|
|
public DbSet<UserDao> Users { get; set; }
|
|
|
|
|
public DbSet<PresenceDao> PresenceDaos { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|