Files
2023-06-26 08:59:00 +02:00

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
{
_ = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("DB"))
? 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);
}
}