2024-11-18 09:39:24 +05:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-11-15 16:29:15 +05:00
|
|
|
using System.Data.Common;
|
2024-11-14 15:17:43 +05:00
|
|
|
|
|
|
|
namespace Persistence.Database.Model;
|
|
|
|
public partial class PersistenceDbContext : DbContext, IPersistenceDbContext
|
|
|
|
{
|
2024-11-15 16:29:15 +05:00
|
|
|
private readonly DbConnection connection = null!;
|
2024-11-14 15:17:43 +05:00
|
|
|
public DbSet<DataSaub> DataSaub => Set<DataSaub>();
|
|
|
|
|
2024-11-18 09:39:24 +05:00
|
|
|
public DbSet<Setpoint> Setpoint => Set<Setpoint>();
|
|
|
|
|
2024-11-15 16:29:15 +05:00
|
|
|
public PersistenceDbContext()
|
|
|
|
: base()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2024-11-18 09:39:24 +05:00
|
|
|
|
2024-11-14 15:17:43 +05:00
|
|
|
public PersistenceDbContext(DbContextOptions<PersistenceDbContext> options)
|
2024-11-15 16:29:15 +05:00
|
|
|
: base(options)
|
2024-11-14 15:17:43 +05:00
|
|
|
{
|
2024-11-15 16:29:15 +05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public PersistenceDbContext(DbConnection connection)
|
|
|
|
{
|
|
|
|
this.connection = connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual DbConnection GetConnection()
|
|
|
|
{
|
|
|
|
return connection;
|
2024-11-14 15:17:43 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
|
|
{
|
|
|
|
if (!optionsBuilder.IsConfigured)
|
|
|
|
optionsBuilder.UseNpgsql("Host=localhost;Database=persistence;Username=postgres;Password=q;Persist Security Info=True;Include Error Detail=True;"
|
|
|
|
//, builder=>builder.EnableRetryOnFailure(2, System.TimeSpan.FromMinutes(1))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
{
|
|
|
|
modelBuilder.HasPostgresExtension("adminpack")
|
|
|
|
.HasAnnotation("Relational:Collation", "Russian_Russia.1251");
|
|
|
|
}
|
|
|
|
|
2024-11-15 16:29:15 +05:00
|
|
|
|
2024-11-14 15:17:43 +05:00
|
|
|
}
|