mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 07:29:00 -07:00
29 lines
915 B
C#
29 lines
915 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Design;
|
|
|
|
namespace RadicadeServer.DB
|
|
{
|
|
public class RecDBContextFactory : IDesignTimeDbContextFactory<RecDBContext>
|
|
{
|
|
public RecDBContext CreateDbContext(string[] args)
|
|
{
|
|
var config = new ConfigurationBuilder()
|
|
.SetBasePath(Directory.GetCurrentDirectory())
|
|
.AddJsonFile("appsettings.json", optional: true)
|
|
.AddJsonFile("appsettings.Development.json", optional: true)
|
|
.AddEnvironmentVariables()
|
|
.Build();
|
|
|
|
var connectionString = config.GetConnectionString("DefaultConnection");
|
|
if (string.IsNullOrWhiteSpace(connectionString))
|
|
throw new InvalidOperationException("Missing ConnectionStrings:DefaultConnection for design-time context creation.");
|
|
|
|
var options = new DbContextOptionsBuilder<RecDBContext>()
|
|
.UseSqlServer(connectionString)
|
|
.Options;
|
|
|
|
return new RecDBContext(options);
|
|
}
|
|
}
|
|
}
|