49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace TURN.Services.Chess.DBModel
|
|
{
|
|
public partial class ModelBaseContext : DbContext
|
|
{
|
|
public ModelBaseContext()
|
|
{
|
|
}
|
|
|
|
public ModelBaseContext(DbContextOptions<ModelBaseContext> options)
|
|
: base(options)
|
|
{
|
|
}
|
|
|
|
public virtual DbSet<Game> Games { get; set; }
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
{
|
|
try
|
|
{
|
|
_ = Environment.GetEnvironmentVariable("DB") != null
|
|
? optionsBuilder.UseNpgsql(Environment.GetEnvironmentVariable("DB"))
|
|
: optionsBuilder.UseNpgsql("Server=localhost;Port=5432;Database=TURNChess;UserId=postgres;" +
|
|
"Password=example;");
|
|
}
|
|
catch (Exception)
|
|
{
|
|
_ = optionsBuilder.UseNpgsql("Server=localhost;Port=5432;Database=TURNChess;UserId=postgres;Password=example;");
|
|
}
|
|
}
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
_ = modelBuilder.Entity<Game>(entity =>
|
|
{
|
|
_ = entity.HasKey(e => e.GameId);
|
|
_ = entity.Property(e => e.GameId)
|
|
.ValueGeneratedOnAdd()
|
|
.HasColumnName("GameId");
|
|
});
|
|
|
|
OnModelCreatingPartial(modelBuilder);
|
|
}
|
|
|
|
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
|
}
|
|
}
|