Selector/Selector.Model/SelectorContext.cs

48 lines
1.4 KiB
C#
Raw Normal View History

2021-10-23 22:16:37 +01:00
using System;
using System.IO;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
2021-10-24 00:23:45 +01:00
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
2021-10-23 22:16:37 +01:00
namespace Selector.Model
{
2021-10-24 00:23:45 +01:00
public class SelectorContext : IdentityDbContext
2021-10-23 22:16:37 +01:00
{
public DbSet<Watcher> Watcher { get; set; }
public SelectorContext(DbContextOptions<SelectorContext> options) : base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
2021-10-24 00:23:45 +01:00
base.OnModelCreating(modelBuilder);
2021-10-23 22:16:37 +01:00
}
}
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<SelectorContext>
{
public SelectorContext CreateDbContext(string[] args)
{
IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(@Directory.GetCurrentDirectory() + "/../Selector.Web/appsettings.Development.json")
.Build();
var builder = new DbContextOptionsBuilder<SelectorContext>();
builder.UseNpgsql(configuration.GetConnectionString("Default"));
return new SelectorContext(builder.Options);
}
}
}