xxxproject/Demo/Data/RemoteData/RemoteDataBase/RemoteDatabaseContex.cs
Class_Student 6b9b5a424f init
2024-10-30 12:11:19 +03:00

40 lines
1.4 KiB
C#

using System;
using Microsoft.EntityFrameworkCore;
using Npgsql;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Threading.Tasks;
using Demo.Data.RemoteData.RemoteDataBase.DAO;
using Demo.domain.Models;
namespace Demo.Data.RemoteData.RemoteDataBase
{
public class RemoteDatabaseContex : 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=45.67.56.214;Port=5421;Username=user9;Database=user9;Password=X8C8NTnD;");
}
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.IsAttedance,
presence.LessonNumber
});
}
}
}