diff options
| author | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-05-06 20:27:38 +0300 |
|---|---|---|
| committer | Syndamia <kamen.d.mladenov@protonmail.com> | 2021-05-06 20:27:38 +0300 |
| commit | 6599716638f4743629eba8daf6c3c04164f5c627 (patch) | |
| tree | 9d7206a18fbba437dd956cca50b9bbe1890798af /ExamTemplate/Data/TemplateContextFactory.cs | |
| parent | 1871676e80c32d556652c969ac8de8be9cf4ae95 (diff) | |
| download | it-kariera-exam-template-6599716638f4743629eba8daf6c3c04164f5c627.tar it-kariera-exam-template-6599716638f4743629eba8daf6c3c04164f5c627.tar.gz it-kariera-exam-template-6599716638f4743629eba8daf6c3c04164f5c627.zip | |
Fixed Data layer not being able to create migrations and added a migration
Diffstat (limited to 'ExamTemplate/Data/TemplateContextFactory.cs')
| -rw-r--r-- | ExamTemplate/Data/TemplateContextFactory.cs | 24 |
1 files changed, 24 insertions, 0 deletions
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<TemplateContext> + { + 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<TemplateContext>() + .UseNpgsql(configuration.GetConnectionString("LocalDBConnection")); + + return new TemplateContext(optionsBuilder.Options); + } + } +} |
