mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-26 23:49:02 -07:00
Radicade Public Code
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user