45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Npgsql;
|
|
using Persistence.Database.Entity;
|
|
using System.Data.Common;
|
|
|
|
namespace Persistence.Database.Model;
|
|
public partial class PersistenceDbContext : DbContext, IPersistenceDbContext
|
|
{
|
|
public DbSet<DataSaub> DataSaub => Set<DataSaub>();
|
|
|
|
public DbSet<Setpoint> Setpoint => Set<Setpoint>();
|
|
|
|
public DbSet<TimestampedSet> TimestampedSets => Set<TimestampedSet>();
|
|
|
|
public PersistenceDbContext()
|
|
: base()
|
|
{
|
|
|
|
}
|
|
|
|
public PersistenceDbContext(DbContextOptions<PersistenceDbContext> options)
|
|
: base(options)
|
|
{
|
|
|
|
}
|
|
|
|
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");
|
|
|
|
modelBuilder.Entity<TimestampedSet>()
|
|
.Property(e => e.Set)
|
|
.HasJsonConversion();
|
|
}
|
|
}
|