Demo/Data/RemoteData/RemoteDataBase/RemoteDataBaseContext.cs

36 lines
1.5 KiB
C#
Raw Permalink Normal View History

2024-10-24 11:13:46 +00:00
using Microsoft.EntityFrameworkCore;
using Posechaemost.Data.RemoteData.RemoteDataBase.DAO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Posechaemost.Data.RemoteData.RemoteDataBase
{
public class RemoteDataBaseContext: DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder){
2024-11-11 20:02:21 +00:00
optionsBuilder.UseNpgsql("Host=localhost; Port=5432; Database=presencedb; Username=postgres; Password=123");
2024-10-24 11:13:46 +00:00
}
protected override void OnModelCreating(ModelBuilder modelBuilder) {
modelBuilder.Entity<GroupDao>().HasKey(group => group.Id);
modelBuilder.Entity<GroupDao>().Property(group => group.Id).ValueGeneratedOnAdd();
2024-11-06 04:10:09 +00:00
modelBuilder.Entity<UserDao>().HasKey(user => user.UserId);
modelBuilder.Entity<UserDao>().Property(user => user.UserId).ValueGeneratedOnAdd();
2024-11-11 20:02:21 +00:00
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);
2024-10-24 11:13:46 +00:00
}
2024-11-11 20:02:21 +00:00
public DbSet<GroupDao> Groups { get; set; }
public DbSet<UserDao> Users { get; set; }
public DbSet<PresenceDao> Presences { get; set; }
2024-10-24 11:13:46 +00:00
}
}