Migration to EF and starting to add Identity #11

Merged
jtom38 merged 16 commits from features/ef-identity-migration into main 2023-07-09 22:19:01 -07:00
2 changed files with 36 additions and 20 deletions
Showing only changes of commit bfd185906c - Show all commits

View File

@ -1,3 +1,5 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Newsbot.Collector.Domain.Consts; using Newsbot.Collector.Domain.Consts;
@ -5,7 +7,7 @@ using Newsbot.Collector.Domain.Entities;
namespace Newsbot.Collector.Database; namespace Newsbot.Collector.Database;
public class DatabaseContext : DbContext public class DatabaseContext : IdentityDbContext
{ {
public DbSet<ArticlesEntity> Articles { get; set; } = null!; public DbSet<ArticlesEntity> Articles { get; set; } = null!;
public DbSet<DiscordQueueEntity> DiscordQueue { get; set; } = null!; public DbSet<DiscordQueueEntity> DiscordQueue { get; set; } = null!;
@ -13,38 +15,51 @@ public class DatabaseContext : DbContext
public DbSet<IconEntity> Icons { get; set; } = null!; public DbSet<IconEntity> Icons { get; set; } = null!;
public DbSet<SourceEntity> Sources { get; set; } = null!; public DbSet<SourceEntity> Sources { get; set; } = null!;
public DbSet<SubscriptionEntity> Subscriptions { get; set; } = null!; public DbSet<SubscriptionEntity> Subscriptions { get; set; } = null!;
private string ConnectionString { get; set; }
public DatabaseContext(IConfiguration appsettings, string connectionString) //public DbSet<UserEntity> Users { get; set; } = null!;
{
var connString = appsettings.GetConnectionString(ConfigConnectionStringConst.Database); private string ConnectionString { get; set; } = "";
ConnectionString = connString ?? "";
} //public DatabaseContext(IConfiguration appsettings, string connectionString)
//{
// var connString = appsettings.GetConnectionString(ConfigConnectionStringConst.Database);
// ConnectionString = connString ?? "";
//}
public DatabaseContext(string connectionString) public DatabaseContext(string connectionString)
{ {
ConnectionString = connectionString; ConnectionString = connectionString;
} }
public DatabaseContext(DbContextOptions<DatabaseContext> connectionString)
{
ConnectionString = "";
}
public DatabaseContext()
{
ConnectionString = "";
}
protected override void OnConfiguring(DbContextOptionsBuilder options) protected override void OnConfiguring(DbContextOptionsBuilder options)
{ {
options.UseNpgsql(ConnectionString); 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) public DatabaseContext(DbContextOptions<DatabaseContext> options, string connectionString)
: base(options) : base(options)
{ {
ConnectionString = connectionString; //ConnectionString = connectionString;
} }
} }

View File

@ -6,6 +6,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="dapper" Version="2.0.123" /> <PackageReference Include="dapper" Version="2.0.123" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.8" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.8"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.8">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>