Newsbot.Collector/Newsbot.Collector.Database/DatabaseContext.cs

65 lines
1.9 KiB
C#

using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Newsbot.Collector.Domain.Consts;
using Newsbot.Collector.Domain.Entities;
namespace Newsbot.Collector.Database;
public class DatabaseContext : IdentityDbContext
{
public DbSet<ArticlesEntity> Articles { get; set; } = null!;
public DbSet<DiscordQueueEntity> DiscordQueue { get; set; } = null!;
public DbSet<DiscordWebhookEntity> DiscordWebhooks { get; set; } = null!;
public DbSet<IconEntity> Icons { get; set; } = null!;
public DbSet<SourceEntity> Sources { get; set; } = null!;
public DbSet<SubscriptionEntity> Subscriptions { get; set; } = null!;
//public DbSet<UserEntity> Users { get; set; } = null!;
private string ConnectionString { get; set; } = "";
//public DatabaseContext(IConfiguration appsettings, string connectionString)
//{
// var connString = appsettings.GetConnectionString(ConfigConnectionStringConst.Database);
// ConnectionString = connString ?? "";
//}
public DatabaseContext(string connectionString)
{
ConnectionString = connectionString;
}
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
if (ConnectionString != "")
{
options.UseNpgsql(ConnectionString);
}
}
//public DatabaseContext(DbContextOptions<DatabaseContext> connectionString)
//{
// ConnectionString = "";
//}
//public DatabaseContext()
//{
// ConnectionString = "";
//}
public DatabaseContext(DbContextOptions<DatabaseContext> options)
: base(options)
{
//ConnectionString = "";
}
public DatabaseContext(DbContextOptions<DatabaseContext> options, string connectionString)
: base(options)
{
//ConnectionString = connectionString;
}
}