new_presence/data/RemoteData/RemoteDatabaseContext.cs
2024-11-16 11:29:24 +03:00

44 lines
1.7 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using data.RemoteData.DAO;
using Microsoft.EntityFrameworkCore;
namespace data.RemoteData
{
public class RemoteDatabaseContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql("Host=45.67.56.214;Port=5421;Username=user11;Database=user11;Password=JSZHJyg1");
}
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
{
presense.Id
});
// Настройка связи UserDao с PresenceDao
modelBuilder.Entity<PresenceDao>()
.Property(presence => presence.Id)
.ValueGeneratedOnAdd();
modelBuilder.Entity<PresenceDao>().HasOne(presence => presence.UserDao).WithMany(user => user.Presences).HasForeignKey(presence => presence.UserGuid);
}
public DbSet<GroupDao> Groups { get; set; }
public DbSet<UserDao> Users { get; set; }
public DbSet<PresenceDao> PresenceDaos { get; set; }
}
}