presence_new/data/RemoteData/RemoteDataBase/RemoteDataBaseContext.cs
2024-11-16 15:02:17 +03:00

36 lines
1.5 KiB
C#
Executable File

using Microsoft.EntityFrameworkCore;
using presence.data.RemoteData.RemoteDataBase.DAO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace presence.data.RemoteData.RemoteDataBase
{
public class RemoteDataBaseContext: DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder){
optionsBuilder.UseNpgsql("Host=localhost; Port=5432; Database=presencedb; Username=postgres; Password=123");
}
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);
modelBuilder.Entity<PresenceDao>().Property(presence=>presence.PresenceId).ValueGeneratedOnAdd();
modelBuilder.Entity<PresenceDao>()
.HasOne(presence => presence.User)
.WithMany(user => user.Presences)
.HasForeignKey(presence => presence.UserId);
}
public DbSet<GroupDao> Groups { get; set; }
public DbSet<UserDao> Users { get; set; }
public DbSet<PresenceDao> Presences { get; set; }
}
}