forked from emonney/QuickApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DesignTimeDbContextFactory.cs
35 lines (30 loc) · 1.12 KB
/
DesignTimeDbContextFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// ======================================
// Author: Ebenezer Monney
// Copyright (c) 2023 www.ebenmonney.com
//
// ==> Gun4Hire: contact@ebenmonney.com
// ======================================
using DAL;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using System;
using System.IO;
using System.Linq;
namespace QuickApp
{
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
{
public ApplicationDbContext CreateDbContext(string[] args)
{
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.AddJsonFile("appsettings.Development.json", optional: true)
.Build();
var builder = new DbContextOptionsBuilder<ApplicationDbContext>();
builder.UseSqlServer(configuration["ConnectionStrings:DefaultConnection"], b => b.MigrationsAssembly("QuickApp"));
return new ApplicationDbContext(builder.Options);
}
}
}