Fix DbContext configuration nightmares.

Thanks to julian figuring out IDesignTimeDbContextFactory exists in #6327.

All this DbContext configuration and options setup stuff is insane. Microsoft should be absolutely ashamed for coming up with this load of garbage.
This commit is contained in:
Pieter-Jan Briers
2022-02-03 03:13:34 +01:00
parent 32a1f6ae93
commit 4da56becab
8 changed files with 44 additions and 46 deletions

View File

@@ -11,22 +11,10 @@ namespace Content.Server.Database
{
public abstract class ServerDbContext : DbContext
{
/// <summary>
/// The "dotnet ef" CLI tool uses the parameter-less constructor.
/// When that happens we want to supply the <see cref="DbContextOptions"/> via <see cref="DbContext.OnConfiguring"/>.
/// To use the context within the application, the options need to be passed the constructor instead.
/// </summary>
protected readonly bool InitializedWithOptions;
public ServerDbContext()
protected ServerDbContext(DbContextOptions options) : base(options)
{
}
public ServerDbContext(DbContextOptions<ServerDbContext> options) : base(options)
{
InitializedWithOptions = true;
}
public DbSet<Preference> Preference { get; set; } = null!;
public DbSet<Profile> Profile { get; set; } = null!;
public DbSet<AssignedUserId> AssignedUserId { get; set; } = null!;