aboutsummaryrefslogtreecommitdiff
path: root/ExamTemplate/Data/TemplateContextFactory.cs
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2021-05-06 20:27:38 +0300
committerSyndamia <kamen.d.mladenov@protonmail.com>2021-05-06 20:27:38 +0300
commit6599716638f4743629eba8daf6c3c04164f5c627 (patch)
tree9d7206a18fbba437dd956cca50b9bbe1890798af /ExamTemplate/Data/TemplateContextFactory.cs
parent1871676e80c32d556652c969ac8de8be9cf4ae95 (diff)
downloadit-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.cs24
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);
+ }
+ }
+}