34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
|
using Demo.Data.RemoteData.RemoteDataBase.DAO;
|
||
|
using Microsoft.EntityFrameworkCore;
|
||
|
|
||
|
namespace Demo.Data.RemoteData.RemoteDataBase
|
||
|
{
|
||
|
public class RemoteDatabaseContext: DbContext
|
||
|
{
|
||
|
public DbSet<GroupDAO> Groups {get; set; }
|
||
|
public DbSet<UserDAO> Users {get; set;}
|
||
|
public DbSet<PresenceDAO> PresenceDaos{get; set; }
|
||
|
|
||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||
|
{
|
||
|
optionsBuilder.UseNpgsql("Host=localhost;" +
|
||
|
"Port=5432;" +
|
||
|
"Username=postgres;" +
|
||
|
"Password=1234;" +
|
||
|
"Database=postgres");
|
||
|
}
|
||
|
|
||
|
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.Guid);
|
||
|
modelBuilder.Entity<UserDAO>().Property(user => user.Guid).ValueGeneratedOnAdd();
|
||
|
modelBuilder.Entity<PresenceDAO>().HasKey(presence => new {
|
||
|
presence.UserGuid,
|
||
|
presence.Date,
|
||
|
presence.LessonNumber
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
}
|