Demo/Data/RemoteData/RemoteDataBase/RemoteDataBaseContext.cs

35 lines
1.3 KiB
C#
Raw 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-06 04:10:09 +00:00
optionsBuilder.UseNpgsql("Host=localhost; 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-10-24 11:13:46 +00:00
modelBuilder.Entity<PresenceDao>().HasKey(presence => new {
presence.User,
presence.Date,
presence.IsAttendence,
presence.ClassNumber
});
}
2024-11-06 04:10:09 +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
}
}