2024-11-14 11:24:07 +00:00
|
|
|
|
using Demo.Data.LocalData.Entity; // Локальные сущности
|
|
|
|
|
using Demo.Data.RemoteData.RemoteDataBase.DAO; // DAO классы
|
2024-10-28 12:42:04 +00:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
public class RemoteDatabaseContext : DbContext
|
|
|
|
|
{
|
2024-11-14 11:24:07 +00:00
|
|
|
|
public DbSet<User> User { get; set; }
|
|
|
|
|
public DbSet<GroupDAO> Group { get; set; } // DbSet для GroupDao
|
|
|
|
|
public DbSet<PresenceDAO> Presence { get; set; } // DbSet для PresenceDao
|
2024-10-28 12:42:04 +00:00
|
|
|
|
|
|
|
|
|
public RemoteDatabaseContext(DbContextOptions<RemoteDatabaseContext> options) : base(options) { }
|
|
|
|
|
|
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
|
|
|
{
|
|
|
|
|
if (!optionsBuilder.IsConfigured)
|
|
|
|
|
{
|
2024-11-14 11:24:07 +00:00
|
|
|
|
optionsBuilder.UseNpgsql("Host=45.67.56.214;Port=5421;Database=;Username=user5;Password=EtEJqhsf");
|
2024-10-28 12:42:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-14 11:24:07 +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.UserId);
|
|
|
|
|
modelBuilder.Entity<UserDAO>().Property(user => user.UserId).ValueGeneratedOnAdd();
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<PresenceDAO>().HasKey(presence => presence.PresenceId); // Устанавливаем первичный ключ
|
|
|
|
|
|
|
|
|
|
// Дополнительные настройки для User
|
|
|
|
|
modelBuilder.Entity<User>(entity =>
|
|
|
|
|
{
|
|
|
|
|
entity.ToTable("User"); // Имя таблицы
|
|
|
|
|
entity.HasKey(e => e.Id); // Указываем первичный ключ
|
|
|
|
|
entity.Property(e => e.FIO)
|
|
|
|
|
.IsRequired()
|
|
|
|
|
.HasColumnName("FIO");
|
|
|
|
|
entity.Property(e => e.GroupID)
|
|
|
|
|
.IsRequired()
|
|
|
|
|
.HasColumnName("GroupID");
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-10-28 12:42:04 +00:00
|
|
|
|
}
|