From 6599716638f4743629eba8daf6c3c04164f5c627 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 6 May 2021 20:27:38 +0300 Subject: Fixed Data layer not being able to create migrations and added a migration --- ExamTemplate/Data/TemplateContextFactory.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 ExamTemplate/Data/TemplateContextFactory.cs (limited to 'ExamTemplate/Data/TemplateContextFactory.cs') diff --git a/ExamTemplate/Data/TemplateContextFactory.cs b/ExamTemplate/Data/TemplateContextFactory.cs new file mode 100644 index 0000000..dff2e9e --- /dev/null +++ b/ExamTemplate/Data/TemplateContextFactory.cs @@ -0,0 +1,24 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Design; +using Microsoft.Extensions.Configuration; +using System.IO; + +namespace ExamTemplate.Data +{ + public class TemplateContextFactory : IDesignTimeDbContextFactory + { + public TemplateContext CreateDbContext(string[] args) + { + var configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory() + "/../Web/") + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddJsonFile("appsettings.Development.json", optional: true) + .Build(); + + var optionsBuilder = new DbContextOptionsBuilder() + .UseNpgsql(configuration.GetConnectionString("LocalDBConnection")); + + return new TemplateContext(optionsBuilder.Options); + } + } +} -- cgit v1.2.3