persistence/DD.Persistence.Database/PersistenceDbContext.cs
ngfrolov 58aa41c1b9
All checks were successful
Unit tests / test (push) Successful in 1m37s
New tagBag scheme tested
2024-12-25 13:27:14 +05:00

51 lines
1.4 KiB
C#

using Microsoft.EntityFrameworkCore;
using DD.Persistence.Database.Entity;
using DD.Persistence.Database.Model;
namespace DD.Persistence.Database;
/// <summary>
/// EF контекст для любых БД поддерживаемых в EF
/// </summary>
public class PersistenceDbContext : DbContext
{
public DbSet<DataSaub> DataSaub => Set<DataSaub>();
public DbSet<TagValue> TagValues => Set<TagValue>();
public DbSet<TagSetValue> TagSetValues => Set<TagSetValue>();
public DbSet<TagBag> TagBag => Set<TagBag>();
public DbSet<Setpoint> Setpoint => Set<Setpoint>();
public DbSet<TimestampedSet> TimestampedSets => Set<TimestampedSet>();
public DbSet<ChangeLog> ChangeLog => Set<ChangeLog>();
public DbSet<TechMessage> TechMessage => Set<TechMessage>();
public DbSet<ParameterData> ParameterData => Set<ParameterData>();
public DbSet<DataSourceSystem> DataSourceSystem => Set<DataSourceSystem>();
public PersistenceDbContext(DbContextOptions options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<TimestampedSet>()
.Property(e => e.Set)
.HasJsonConversion();
modelBuilder.Entity<ChangeLog>()
.Property(e => e.Value)
.HasJsonConversion();
modelBuilder.Entity<TagBag>()
.Property(e => e.Values)
.HasJsonConversion();
}
}