using System; using System.IO; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; using Microsoft.Extensions.Configuration; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; namespace Selector.Model { public class ApplicationDbContext : IdentityDbContext { public DbSet Watcher { get; set; } public ApplicationDbContext(DbContextOptions options) : base(options) { } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity() .HasOne(w => w.User) .WithMany(u => u.Watchers) .HasForeignKey(w => w.UserId); SeedData.Seed(modelBuilder); } } public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory { public ApplicationDbContext CreateDbContext(string[] args) { IConfigurationRoot configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile(@Directory.GetCurrentDirectory() + "/../Selector.Web/appsettings.Development.json") .Build(); var builder = new DbContextOptionsBuilder(); builder.UseNpgsql(configuration.GetConnectionString("Default")); return new ApplicationDbContext(builder.Options); } } }