Files
Assignment6/Data/PostgresApplicationDbContextFactory.cs
Chris 30a86a5890
All checks were successful
Build and Push Docker Image / docker (push) Successful in 48s
reworking git structure
2026-04-08 12:30:29 +00:00

20 lines
816 B
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
namespace Example.Data;
public sealed class PostgresApplicationDbContextFactory : IDesignTimeDbContextFactory<PostgresApplicationDbContext>
{
public PostgresApplicationDbContext CreateDbContext(string[] args)
{
var configuration = DesignTimeConfiguration.Create(includeDevelopmentSettings: false);
var connectionString = configuration.GetConnectionString("DefaultConnection")
?? throw new InvalidOperationException("Connection string 'DefaultConnection' was not found.");
var optionsBuilder = new DbContextOptionsBuilder<PostgresApplicationDbContext>();
optionsBuilder.UseNpgsql(connectionString);
return new PostgresApplicationDbContext(optionsBuilder.Options);
}
}