35 lines
1.0 KiB
C#
35 lines
1.0 KiB
C#
using FinlyticCore.Database;
|
|
using FinlyticCore.Entities.Settings;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace FinlyticNotify.Database;
|
|
|
|
/// <summary>
|
|
/// Entity Framework DbContext used by FinlyticNotify exclusively for its own database (finlytic_notify)
|
|
/// and dynamic settings.
|
|
/// </summary>
|
|
public class NotifyDbContext : DbContext, ISettingsDbContext
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="NotifyDbContext"/> class.
|
|
/// </summary>
|
|
public NotifyDbContext(DbContextOptions<NotifyDbContext> options) : base(options)
|
|
{
|
|
}
|
|
|
|
/// <summary>Dynamic settings table for FinlyticNotify.</summary>
|
|
public DbSet<SettingEntity> DynamicSettings => Set<SettingEntity>();
|
|
|
|
/// <inheritdoc />
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
modelBuilder.Entity<SettingEntity>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id);
|
|
entity.HasIndex(e => e.Key).IsUnique();
|
|
});
|
|
}
|
|
}
|