You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
leap-hit-server/code/server/DataBase/Context/PongDbContext.cs

40 lines
1.4 KiB

using DataBase.Entity;
using Microsoft.EntityFrameworkCore;
using System.Diagnostics;
using System.Reflection;
namespace DataBase.Context
{
public class PongDbContext : DbContext
{
public DbSet<Player> Players { get; set; }
public DbSet<Game> Games { get; set; }
public DbSet<Message> Messages { get; set; }
public DbSet<Chat> Chats { get; set; }
public PongDbContext() { }
public PongDbContext(DbContextOptions<PongDbContext> options) : base(options) { }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
//base.OnConfiguring(optionsBuilder);
if (!optionsBuilder.IsConfigured)
{
//optionsBuilder.UseNpgsql(@"host=localhost;database=postgres;user id=postgres;password=1234;");
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..\\..\\..\\..\\DataBase\\PongDB.db");
optionsBuilder.UseSqlite($"Data Source={path}");
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Player>().ToTable("Players");
modelBuilder.Entity<Game>().ToTable("Games");
modelBuilder.Entity<Message>().ToTable("Messages");
modelBuilder.Entity<Chat>().ToTable("Chats");
}
}
}