semesterWork/data/RemoteDatabaseContext.cs

33 lines
993 B
C#
Raw Permalink Normal View History

2024-11-16 12:34:29 +00:00
using data.DAO;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace data
{
public class RemoteDatabaseContext: DbContext
2024-11-16 12:34:29 +00:00
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql("Host=localhost;port=5432;Password=admin;Username=postgres;Database=semesterWork");
}
public DbSet<GroupDAO> groups { get; set; }
2024-11-16 12:34:29 +00:00
public DbSet<UserDAO> users { get; set; }
2024-11-16 12:34:29 +00:00
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<UserDAO>().HasKey(it => it.Guid);
modelBuilder.Entity<GroupDAO>().HasKey(it => it.Id);
modelBuilder.Entity<UserDAO>().Property(it => it.Guid).ValueGeneratedOnAdd();
modelBuilder.Entity<GroupDAO>().Property(it => it.Id).ValueGeneratedOnAdd();
}
}
}